当前位置: 首页>>代码示例>>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;未经允许,请勿转载。