本文整理匯總了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();