protected function _processTask() { try { $curl = new Curl(); $curl->setUserAgent('got/Tarth'); if ($this->includeTarthHeader) { $curl->setHeader(\Tarth\Tool\Task::HEADER_ALLERIA_CRC, \Tarth\Tool\Task::getTarthHeader($this)); } if (isset($this->header)) { foreach ($this->header as $key => $value) { $curl->setHeader($key, $value); } } call_user_func_array(array($curl, strtolower($this->method)), array($this->url, $this->data)); if ($curl->error) { return false; } else { //响应码大于300为请求失败 return $curl->httpStatusCode < 300; //接口返回为json格式,返回值中有code为0 //return $curl->response->code == 0; } } catch (Exception $e) { } }
<?php require 'include.php'; $task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=timer&time=' . time()); $task->runAfter(100); echo \Tarth\Tool\Task::exec();
<?php require_once __DIR__ . '/../vendor/autoload.php'; $taskId = isset($argv[1]) ? intval($argv[1]) : 0; if ($taskId == 0) { echo "Task id is invalid."; } echo \Tarth\Tool\Task::closeTask($taskId);