public function indexOp() { if (ob_get_level()) { ob_end_clean(); } $logic_queue = Logic('queue'); $worker = new QueueServer(); $queues = $worker->scan(); while (true) { $content = $worker->pop($queues, 1800); if (is_array($content)) { $method = key($content); $arg = current($content); $result = $logic_queue->{$method}($arg); if (!$result['state']) { $this->log($result['msg'], false); } // echo date('Y-m-d H:i:s',time()).' '.$method."\n"; // flush(); // ob_flush(); } else { $model = Model(); $model->checkActive(); unset($model); // echo date('Y-m-d H:i:s',time())." ---\n"; // flush(); // ob_flush(); } } }
public function queueOp() { if (ob_get_level()) { ob_end_clean(); } $model_queue = Model('queue', BASE_PATH); $worker = new QueueServer(); while (true) { $list_key = $worker->scan(); if (!empty($list_key) && is_array($list_key)) { foreach ($list_key as $key) { $content = $worker->pop($key); if (empty($content)) { continue; } $method = key($content); $arg = current($content); $model_queue->{$method}($arg); echo date('Y-m-d H:i:s', time()) . ' ' . $method . "\n"; // $content['time'] = date('Y-m-d H:i:s',time()); // print_R($content); // echo "\n"; flush(); ob_flush(); } } sleep(1); } }
* @return bool whether $url exceeds the hourly quota of the site it is from */ function withinQuota($url) { if (!($site = UrlParser::urlMemberSiteArray($url, $this->quota_sites_keys, "q" . $this->allow_disallow_cache_time, true))) { return true; } list($quota, $current_count) = $this->quota_sites[$site]; if ($current_count < $quota) { $this->quota_sites[$site] = array($quota, $current_count + 1); $flag = true; } else { $flag = false; } if ($this->quota_clear_time + ONE_HOUR < time()) { $this->quota_clear_time = time(); foreach ($this->quota_sites as $site => $info) { list($quota, ) = $info; $this->quota_sites[$site] = array($quota, 0); } } return $flag; } } if (!defined("UNIT_TEST_MODE")) { /* * Instantiate and runs the QueueSever */ $queue_server = new QueueServer($INDEXED_FILE_TYPES); $queue_server->start(); }
<?php require __DIR__ . '/classes/Server.php'; $serv = new QueueServer(); $serv->listen();