當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Scheduler::newTask方法代碼示例

本文整理匯總了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();
}
開發者ID:hrach,項目名稱:async-task-tree,代碼行數:7,代碼來源:functions.php

示例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);
開發者ID:xiaobudongzhang,項目名稱:lib,代碼行數:31,代碼來源:SchedulerTest.php

示例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();
開發者ID:chendeng,項目名稱:php-lib,代碼行數:31,代碼來源:server-non-block.php

示例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();
開發者ID:EdenChan,項目名稱:Instances,代碼行數:22,代碼來源:Client.php

示例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();
開發者ID:chendeng,項目名稱:php-lib,代碼行數:31,代碼來源:cooperative-multitask.php

示例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();
開發者ID:hitoy,項目名稱:Ideas-and-Experiments,代碼行數:31,代碼來源:coroutine.php

示例7: Scheduler

<?php

require_once 'Autoloader.php';
require_once 'functions.php';
$scheduler = new Scheduler();
$scheduler->newTask(parentTask());
$scheduler->run();
開發者ID:JosephineCoder,項目名稱:php_examples,代碼行數:7,代碼來源:driver.php


注:本文中的Scheduler::newTask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。