本文整理汇总了PHP中Scheduler::newTask方法的典型用法代码示例。如果您正苦于以下问题:PHP Scheduler::newTask方法的具体用法?PHP Scheduler::newTask怎么用?PHP Scheduler::newTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scheduler
的用法示例。
在下文中一共展示了Scheduler::newTask方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
function run()
{
$default = TasksHolder::$tasks['default'];
$scheduler = new Scheduler();
$scheduler->newTask($default);
$scheduler->run();
}
示例2: taskTest
{
for ($i = 1; $i < $max; ++$i) {
echo "{$msg} iteration {$i}\n";
yield;
}
}
function taskTest()
{
$x = echoTimes('foo', 10);
$x->send("dd");
$x->send("dd");
$x->send("dd");
echo "----\n";
echoTimes('bar', 5);
yield;
}
function taskerror()
{
try {
(yield killTask(500));
} catch (Exception $e) {
echo "try to kill task failed", $e->getMessage(), "\n";
}
}
$scheduler = new Scheduler();
//$scheduler->newTask(taskTest());
$scheduler->newTask(server(8010));
$scheduler->newTask(server(8011));
$scheduler->newTask(server(8012));
$scheduler->run();
//server(8002);
示例3: handleClient
(yield waitForRead($socket));
$clientSocket = stream_socket_accept($socket, 0);
echo "server:handleClient\n";
(yield newTask(handleClient($clientSocket)));
}
}
function handleClient($socket)
{
echo "handclient:waitForRead\n";
(yield waitForRead($socket));
echo "handclient:Read\n";
$data = fread($socket, 8192);
$msg = "Received following request:\n\n{$data}";
$msgLength = strlen($msg);
$response = <<<RES
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: {$msgLength}
Connection: close
{$msg}
RES;
echo "handclient:waitForWrite\n";
(yield waitForWrite($socket));
echo "handclient:Write\n";
fwrite($socket, $response);
fclose($socket);
}
$scheduler = new Scheduler();
$scheduler->newTask(server(8000));
$scheduler->run();
示例4: task1
<?php
include_once 'Task.php';
include_once 'Scheduler.php';
function task1()
{
for ($i = 1; $i <= 10; ++$i) {
echo "This is task 1 iteration {$i}.\n";
yield;
}
}
function task2()
{
for ($i = 1; $i <= 5; ++$i) {
echo "This is task 2 iteration {$i}.\n";
yield;
}
}
$scheduler = new Scheduler();
$scheduler->newTask(task1());
$scheduler->newTask(task2());
$scheduler->run();
示例5: childTask
unset($this->taskMap[$task->getTaskId()]);
} else {
$this->schedule($task);
}
}
}
}
//Lets try out scheduler with an example:
function childTask()
{
$tid = (yield getTaskId());
while (true) {
echo "Child task {$tid} still alive!\n";
yield;
}
}
function task()
{
$tid = (yield getTaskId());
$childTid = (yield newTask(childTask()));
for ($i = 1; $i <= 6; ++$i) {
echo "Parent task {$tid} iteration {$i}.\n";
yield;
if ($i == 3) {
(yield killTask($childTid));
}
}
}
$scheduler = new Scheduler();
$scheduler->newTask(task());
$scheduler->run();
示例6: __construct
protected $callback;
public function __construct(callable $callback)
{
$this->callback = $callback;
}
public function __invoke(Task $task, Scheduler $scheduler)
{
$callback = $this->callback;
return $callback($task, $scheduler);
}
}
function getTaskId()
{
return new SystemCall(function (Task $task, Scheduler $scheduler) {
$task->setSendValue($task->getTaskId());
$scheduler->schedule($task);
});
}
function task($max)
{
$tid = (yield getTaskId());
// <-- here's the syscall!
for ($i = 1; $i <= $max; ++$i) {
echo "This is task {$tid} iteration {$i}.\n";
yield;
}
}
$scheduler = new Scheduler();
$scheduler->newTask(task(10));
$scheduler->newTask(task(5));
$scheduler->run();
示例7: Scheduler
<?php
require_once 'Autoloader.php';
require_once 'functions.php';
$scheduler = new Scheduler();
$scheduler->newTask(parentTask());
$scheduler->run();