function TimingTask() { // load urls $mysql = new SaeMysql(); $sql = "SELECT url FROM `url`"; $data = $mysql->getData( $sql ); $mysql->closeDb(); $queue = new SaeTaskQueue('task_queue_0_2'); $array = array(); for($i = 0; $i < sizeof($data); ++$i) { //$array[] = array('url'=>"http://urlwatcher.sinaapp.com/url_watch.php", "postdata"=>"target=".$data[$i], "prior"=>true); $array[] = array('url'=>"http://urlwatcher.sinaapp.com/url_watch.php?target=" . $data[$i]["url"], "postdata"=>NULL, "prior"=>true); } $queue->addTask($array); $ret = $queue->push(); if ($ret === false) { var_dump($queue->errno(), $queue->errmsg()); echo "Failed."; } else { echo "Success."; print_r($array); } }
public function timerAction() { $tasks = array(); $list = Ysu_LibraryModel::select_all(); if (empty($list)) { echo 'no task'; exit; } $queue = new SaeTaskQueue('ysulibrary'); foreach ($list as $v) { $tasks[] = array('url' => '/ysu/task', 'postdata' => 'param=' . json_encode($v)); } $queue->addTask($tasks); $ret = $queue->push(); if ($ret === false) { var_dump($queue->errno(), $queue->errmsg()); } else { echo 'total task: ' . count($list); } }
function cron($start = 0, $limit = 70, $schema_id = 0) { global $_db; $where = "WHERE `status` = 'on'"; if ($schema_id > 0) { $where .= " AND schema_id = {$schema_id}"; $start = 0; $limit = 1; } $sql = "SELECT * FROM `schemas` {$where} LIMIT {$start},{$limit}"; $schemas = $_db->get_results($sql); fetch_web($schemas); return count($schemas); } if (is_numeric($_REQUEST['start'])) { echo cron($_REQUEST['start'], $_REQUEST['limit']); } elseif (empty($_REQUEST['start'])) { $total = $_db->get_var("SELECT count(*) FROM `schemas` WHERE `status` = 'on'"); $queue = new SaeTaskQueue("cron_tail"); $array = array(); for ($i = 0; $i <= $total + 70; $i += 70) { $array[] = array('url' => "http://pickcat.sinaapp.com/cron.php", "postdata" => "start={$i}&limit=70"); } $queue->addTask($array); $ret = $queue->push(); if ($ret === false) { var_dump($queue->errno(), $queue->errmsg()); } else { echo 'true'; } }