当前位置: 首页>>代码示例>>PHP>>正文


PHP swoole_server::after方法代码示例

本文整理汇总了PHP中swoole_server::after方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::after方法的具体用法?PHP swoole_server::after怎么用?PHP swoole_server::after使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swoole_server的用法示例。


在下文中一共展示了swoole_server::after方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message From Client {$fd}:{$data}\n";
     $param = array('fd' => $fd, 'msg' => $data);
     $str = json_encode($param);
     $serv->after(1000, array($this, 'onAfter'), $str);
 }
开发者ID:ppker,项目名称:swoole-doc,代码行数:7,代码来源:swoole_after_server.php

示例2: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}");
    $cmd = trim($data);
    if ($cmd == "reload") {
        $serv->reload();
    } elseif ($cmd == "task") {
        $serv->task("task-" . $fd);
    } elseif ($cmd == "taskwait") {
        $result = $serv->taskwait("taskwait");
        if ($result) {
            $serv->send($fd, "taskwaitok");
        }
    } elseif ($cmd == "taskWaitMulti") {
        $tasks = array('taskWaitMulti', 'taskWaitMulti');
        $result = $serv->taskWaitMulti($tasks);
        if (is_array($result)) {
            $serv->send($fd, "taskWaitMulti OK");
        } else {
            $serv->send($fd, "taskWaitMulti error");
        }
    } elseif ($cmd == "hellotask") {
        $serv->task("hellotask");
    } elseif ($cmd == "sendto") {
        $serv->sendto("127.0.0.1", 9999, "hello world");
    } elseif ($cmd == "close") {
        $serv->close($fd);
    } elseif ($cmd == "info") {
        $info = $serv->connection_info(strval($fd), $from_id);
        $serv->send($fd, serialize($info));
    } elseif ($cmd == 'proxy') {
        $serv->send(1, "hello world\n");
    } elseif ($cmd == 'sleep') {
        sleep(10);
    } elseif ($cmd == 'sendfile') {
        $serv->sendfile($fd, __DIR__ . '/test.jpg');
    } elseif ($cmd == 'foreach') {
        foreach ($serv->connections as $fd) {
            echo "conn : {$fd}\n";
        }
        return;
    } elseif ($cmd == 'tick') {
        $serv->tick(1000, function ($id) use($serv, $fd) {
            $serv->send($fd, "tick");
            $serv->clearTimer($id);
        });
    } elseif ($cmd == 'after') {
        $serv->after(1000, function ($id) use($serv, $fd) {
            $serv->send($fd, "after");
        });
    } elseif ($cmd == "list") {
        $start_fd = 0;
        echo "broadcast\n";
        while (true) {
            $conn_list = $serv->connection_list($start_fd, 10);
            if (empty($conn_list)) {
                echo "iterates finished\n";
                break;
            }
            $start_fd = end($conn_list);
            var_dump($conn_list);
        }
    } elseif ($cmd == "list2") {
        foreach ($serv->connections as $con) {
            var_dump($serv->connection_info($con));
        }
    } elseif ($cmd == "stats") {
        $serv_stats = $serv->stats();
        $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . "\ncount=" . count($serv->connections) . PHP_EOL);
    } elseif ($cmd == "broadcast") {
        broadcast($serv, $fd, "hello from {$fd}\n");
    } elseif ($cmd == "error") {
        hello_no_exists();
    } elseif ($cmd == "exit") {
        exit("worker php exit.\n");
    } elseif (substr($cmd, 0, 5) == "close") {
        $close_fd = substr($cmd, 6);
        $serv->close($close_fd);
    } elseif ($cmd == "shutdown") {
        $serv->shutdown();
    } elseif ($cmd == "fatalerror") {
        require __DIR__ . '/php/error.php';
    } elseif ($cmd == 'sendbuffer') {
        $buffer = G::getBuffer($fd);
        $buffer->append("hello\n");
        $serv->send($fd, $buffer);
    } elseif ($cmd == 'defer') {
        $serv->defer(function () use($fd, $serv) {
            $serv->close($fd);
            $serv->defer(function () {
                echo "deferd\n";
            });
        });
        $serv->send($fd, 'Swoole: ' . $data, $from_id);
    } elseif ($cmd == 'big_resp') {
        $serv->send($fd, str_repeat('A', 256 * 1024));
    } elseif ($cmd == 'big_task') {
        $serv->task($fd . ' ' . str_repeat('A', 256 * 1024 - 8));
    } else {
        $serv->send($fd, 'Swoole: ' . $data, $from_id);
//.........这里部分代码省略.........
开发者ID:swoole,项目名称:tests,代码行数:101,代码来源:server.php

示例3: setTimerInWorker

function setTimerInWorker(swoole_server $serv, $worker_id)
{
    if ($worker_id == 0) {
        echo "Start: " . microtime(true) . "\n";
        $serv->addtimer(3000);
        $serv->addtimer(7000);
        //var_dump($serv->gettimer());
    }
    $serv->after(2000, function () {
        echo "Timeout: " . microtime(true) . "\n";
    });
    $serv->after(5000, function () {
        echo "Timeout: " . microtime(true) . "\n";
        global $serv;
        $serv->deltimer(3000);
    });
}
开发者ID:jinguanio,项目名称:swoolecrawler,代码行数:17,代码来源:server.php


注:本文中的swoole_server::after方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。