Task类
此类是任务类,其成员方法一般在组件的回调API中调用。
creatTask ( $task_options = [] ) : boolean | int
参数
@param array $task_options 任务参数选项
含义
创建一条任务
举例
<?php
use PHPCreeper\Producer;
use PHPCreeper\Kernel\Task;
$producer = new Producer;
$task_options = [
'method' => 'get',
'url' => 'http://www.baidu.com',
];
//直接调用【不推荐】
Task::creatTask($task_options);
//通过phpcreeper实例调用【推荐】
$producer->onProducerStart = function($producer){
$producer->creatTask($task_options);
};
creatMultiTask ( $task_options = [] ) : boolean | int
参数
@param string | 1D-array | 2D-array $task 任务参数选项
含义
创建多条任务
举例
<?php
use PHPCreeper\Producer;
use PHPCreeper\Kernel\Task;
$producer = new Producer;
$task_options = [
[
'method' => 'get',
'url' => 'http://www.baidu.com',
],
[
'method' => 'get',
'url' => 'http://www.qq.com',
],
];
//直接调用【不推荐】
Task::creatMultiTask($task_options);
//通过phpcreeper实例调用【推荐】
$producer->onProducerStart = function($producer){
$producer->creatMultiTask($task_options);
};