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


PHP swoole_server::stats方法代码示例

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


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

示例1: onReceive

 public function onReceive(\swoole_server $server, $fd, $from_id, $data)
 {
     $data = trim($data);
     if ($data == 'Stop') {
         //停止
         $server->shutdown();
         $server->send($fd, 'success', $from_id);
     } else {
         if ($data == 'Stats') {
             //状态
             $data = $server->stats();
             $server->send($fd, json_encode($data), $from_id);
         } else {
             if ($data == 'Reload') {
                 //重启
                 $server->reload();
                 $server->send($fd, 'success', $from_id);
             } else {
                 if ($data == 'ResetTelnet') {
                     //重置所有telnet链接
                 } else {
                     $data = json_decode($data, true);
                     if ($data['act'] == 'Telnet' && isset($data['ip']) && isset($data['cmd'])) {
                         //执行命令
                         $service = TelnetEvent::getService($data['ip']);
                         if ($service == null) {
                             $result['code'] = 2;
                         } else {
                             if ($data['cmd'] > 0) {
                                 if (isset($data['arg'])) {
                                     $result['data'] = $service->exec($data['cmd'], $data['arg']);
                                 } else {
                                     $result['data'] = $service->exec($data['cmd']);
                                 }
                                 if ($result == null || $result['data'] == null) {
                                     $result = ['code' => 3];
                                 } else {
                                     $result['code'] = 1;
                                 }
                             } else {
                                 $service->getSwitch()->connect();
                                 if ($service->getSwitch()->isConnect()) {
                                     $result['code'] = 1;
                                 } else {
                                     $result['code'] = 3;
                                 }
                             }
                         }
                         $server->send($fd, json_encode($result), $from_id);
                     } else {
                         $server->send($fd, 'unknown command!', $from_id);
                     }
                 }
             }
         }
     }
     $server->close($fd);
 }
开发者ID:picone,项目名称:SwitchManage,代码行数:58,代码来源:IndexController.class.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") {
        $task_id = $serv->task("task-" . $fd);
        echo "Dispath AsyncTask: id={$task_id}\n";
    } elseif ($cmd == "taskwait") {
        $result = $serv->taskwait("taskwait");
        if ($result) {
            $serv->send($fd, "taskwaitok");
        }
        echo "SyncTask: result=" . var_export($result, true) . "\n";
    } elseif ($cmd == "hellotask") {
        $serv->task("hellotask");
    } elseif ($cmd == "sendto") {
        $serv->sendto("127.0.0.1", 9999, "hello world");
    } elseif ($cmd == "close") {
        $serv->send($fd, "close connection\n");
        $result = $serv->close($fd);
    } elseif ($cmd == "info") {
        $info = $serv->connection_info(strval($fd), $from_id);
        var_dump($info["remote_ip"]);
        $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
    } elseif ($cmd == 'proxy') {
        $serv->send(1, "hello world\n");
    } elseif ($cmd == 'sleep') {
        sleep(10);
    } elseif ($cmd == 'foreach') {
        foreach ($serv->connections as $fd) {
            echo "conn : {$fd}\n";
        }
        return;
    } elseif ($cmd == 'tick') {
        $serv->tick(2000, function ($id) {
            echo "tick #{$id}\n";
        });
    } elseif ($cmd == 'addtimer') {
        $serv->addtimer(3000);
    } 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) . 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 == 'sendbuffer') {
        $buffer = G::getBuffer($fd);
        $buffer->append("hello\n");
        $serv->send($fd, $buffer);
    } else {
        $ret = $serv->send($fd, 'Swoole: ' . $data, $from_id);
        var_dump($ret);
        //$serv->close($fd);
    }
    //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data";
    //    $serv->after(
    //        800, function () {
    //            echo "hello";
    //        }
    //    );
    //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id);
}
开发者ID:WenkeZhou,项目名称:swoole-src,代码行数:88,代码来源:server.php

示例3: intval

    $data = intval($data);
    for ($i = 0; $i < $data; $i++) {
        $tid = mt_rand(0, 1);
        echo "data:{$i} to task: {$tid} " . PHP_EOL;
        $serv->task($i, $tid);
    }
});
$serv->on('Task', function (swoole_server $serv, $task_id, $from_id, $data) {
    echo "onTask: [PID=" . posix_getpid() . "]: task_id={$task_id}, data_len=" . strlen($data) . "." . PHP_EOL;
    sleep(10);
    //$serv->finish($data);
    echo 'finish' . PHP_EOL;
    return;
});
$serv->on('Finish', function (swoole_server $serv, $task_id, $data) {
    echo "Task#{$task_id} finished, data_len=" . strlen($data) . PHP_EOL;
});
$serv->on('Timer', function (swoole_server $serv, $time) {
    echo "{$time} call" . PHP_EOL;
    print_r($serv->stats());
});
$serv->on('workerStart', function ($serv, $worker_id) {
    global $argv;
    if ($worker_id >= $serv->setting['worker_num']) {
        swoole_set_process_name("php {$argv[0]}: task_worker");
    } else {
        $serv->addtimer(5000);
        swoole_set_process_name("php {$argv[0]}: worker");
    }
});
$serv->start();
开发者ID:liangkwok,项目名称:Swoole,代码行数:31,代码来源:task_num.php

示例4: onReceive

 public function onReceive(\swoole_server $server, $fd, $fromId, $data)
 {
     if ($data == $this->preSysCmd . "reload") {
         $ret = intval($server->reload());
         $server->send($fd, $ret);
     } elseif ($data == $this->preSysCmd . "info") {
         $info = $server->connection_info($fd);
         $server->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
     } elseif ($data == $this->preSysCmd . "stats") {
         $serv_stats = $server->stats();
         $server->send($fd, 'Stats: ' . var_export($serv_stats, true) . PHP_EOL);
     } elseif ($data == $this->preSysCmd . "shutdown") {
         $server->shutdown();
     } else {
         $this->protocol->onReceive($server, $fd, $fromId, $data);
     }
 }
开发者ID:vzina,项目名称:esaywork,代码行数:17,代码来源:ServerAbstract.php

示例5: 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

示例6: onReceive

 public final function onReceive(\swoole_server $serv, $fd, $from_id, $data)
 {
     $requestInfo = Packet::packDecode($data);
     #decode error
     if ($requestInfo["code"] != 0) {
         $pack["guid"] = $requestInfo["guid"];
         $req = Packet::packEncode($requestInfo);
         $serv->send($fd, $req);
         return true;
     } else {
         $requestInfo = $requestInfo["data"];
     }
     #api was not set will fail
     if (!is_array($requestInfo["api"]) && count($requestInfo["api"])) {
         $pack = Packet::packFormat("param api is empty", 100003);
         $pack["guid"] = $requestInfo["guid"];
         $pack = Packet::packEncode($pack);
         $serv->send($fd, $pack);
         return true;
     }
     $guid = $requestInfo["guid"];
     //prepare the task parameter
     $task = array("type" => $requestInfo["type"], "guid" => $requestInfo["guid"], "fd" => $fd, "protocol" => "tcp");
     //different task type process
     switch ($requestInfo["type"]) {
         case DoraConst::SW_MODE_WAITRESULT_SINGLE:
             $task["api"] = $requestInfo["api"]["one"];
             $taskid = $serv->task($task);
             //result with task key
             $this->taskInfo[$fd][$guid]["taskkey"][$taskid] = "one";
             return true;
             break;
         case DoraConst::SW_MODE_NORESULT_SINGLE:
             $task["api"] = $requestInfo["api"]["one"];
             $serv->task($task);
             //return success deploy
             $pack = Packet::packFormat("transfer success.已经成功投递", 100001);
             $pack["guid"] = $task["guid"];
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             return true;
             break;
         case DoraConst::SW_MODE_WAITRESULT_MULTI:
             foreach ($requestInfo["api"] as $k => $v) {
                 $task["api"] = $requestInfo["api"][$k];
                 $taskid = $serv->task($task);
                 $this->taskInfo[$fd][$guid]["taskkey"][$taskid] = $k;
             }
             return true;
             break;
         case DoraConst::SW_MODE_NORESULT_MULTI:
             foreach ($requestInfo["api"] as $k => $v) {
                 $task["api"] = $requestInfo["api"][$k];
                 $serv->task($task);
             }
             $pack = Packet::packFormat("transfer success.已经成功投递", 100001);
             $pack["guid"] = $task["guid"];
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             return true;
             break;
         case DoraConst::SW_CONTROL_CMD:
             switch ($requestInfo["api"]["cmd"]["name"]) {
                 case "getStat":
                     $pack = Packet::packFormat("OK", 0, array("server" => $serv->stats()));
                     $pack["guid"] = $task["guid"];
                     $pack = Packet::packEncode($pack);
                     $serv->send($fd, $pack);
                     return true;
                     break;
                 case "reloadTask":
                     $pack = Packet::packFormat("OK", 0, array("server" => $serv->stats()));
                     $pack["guid"] = $task["guid"];
                     $pack = Packet::packEncode($pack);
                     $serv->send($fd, $pack);
                     $serv->reload(true);
                     return true;
                     break;
                 default:
                     $pack = Packet::packFormat("unknow cmd", 100011);
                     $pack = Packet::packEncode($pack);
                     $serv->send($fd, $pack);
                     unset($this->taskInfo[$fd]);
                     break;
             }
             break;
         case DoraConst::SW_MODE_ASYNCRESULT_SINGLE:
             $task["api"] = $requestInfo["api"]["one"];
             $taskid = $serv->task($task);
             $this->taskInfo[$fd][$guid]["taskkey"][$taskid] = "one";
             //return success
             $pack = Packet::packFormat("transfer success.已经成功投递", 100001);
             $pack["guid"] = $task["guid"];
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             return true;
             break;
         case DoraConst::SW_MODE_ASYNCRESULT_MULTI:
             foreach ($requestInfo["api"] as $k => $v) {
                 $task["api"] = $requestInfo["api"][$k];
//.........这里部分代码省略.........
开发者ID:xcl3721,项目名称:dora-rpc,代码行数:101,代码来源:Server.php

示例7: onReceive

 public final function onReceive(\swoole_server $serv, $fd, $from_id, $data)
 {
     $reqa = Packet::packDecode($data);
     #decode error
     if ($reqa["code"] != 0) {
         $req = Packet::packEncode($reqa);
         $serv->send($fd, $req);
         return true;
     } else {
         $req = $reqa["data"];
     }
     #api not set
     if (!is_array($req["api"]) && count($req["api"])) {
         $pack = Packet::packFormat("param api is empty", 100003);
         $pack["guid"] = $req["guid"];
         $pack = Packet::packEncode($pack);
         $serv->send($fd, $pack);
         return true;
     }
     $this->taskInfo[$fd] = $req;
     $task = array("type" => $this->taskInfo[$fd]["type"], "guid" => $this->taskInfo[$fd]["guid"], "fd" => $fd);
     switch ($this->taskInfo[$fd]["type"]) {
         case DoraConst::SW_SYNC_SINGLE:
             $task["api"] = $this->taskInfo[$fd]["api"]["one"];
             $taskid = $serv->task($task);
             $this->taskInfo[$fd]["task"][$taskid] = "one";
             return true;
             break;
         case DoraConst::SW_ASYNC_SINGLE:
             $task["api"] = $this->taskInfo[$fd]["api"]["one"];
             $serv->task($task);
             $pack = Packet::packFormat("transfer success.已经成功投递", 100001);
             $pack["guid"] = $task["guid"];
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             unset($this->taskInfo[$fd]);
             return true;
             break;
         case DoraConst::SW_SYNC_MULTI:
             foreach ($req["api"] as $k => $v) {
                 $task["api"] = $this->taskInfo[$fd]["api"][$k];
                 $taskid = $serv->task($task);
                 $this->taskInfo[$fd]["task"][$taskid] = $k;
             }
             return true;
             break;
         case DoraConst::SW_ASYNC_MULTI:
             foreach ($req["api"] as $k => $v) {
                 $task["api"] = $this->taskInfo[$fd]["api"][$k];
                 $serv->task($task);
             }
             $pack = Packet::packFormat("transfer success.已经成功投递", 100001);
             $pack["guid"] = $task["guid"];
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             unset($this->taskInfo[$fd]);
             return true;
             break;
         case DoraConst::SW_CONTROL_CMD:
             if ($this->taskInfo[$fd]["api"]["cmd"]["name"] == "getStat") {
                 $pack = Packet::packFormat("OK", 0, array("server" => $serv->stats()));
                 $pack["guid"] = $task["guid"];
                 $pack = Packet::packEncode($pack);
                 $serv->send($fd, $pack);
                 unset($this->taskInfo[$fd]);
                 return true;
             }
             //no one process
             $pack = Packet::packFormat("unknow cmd", 100011);
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             unset($this->taskInfo[$fd]);
             break;
         default:
             $pack = Packet::packFormat("unknow task type.未知类型任务", 100002);
             $pack = Packet::packEncode($pack);
             $serv->send($fd, $pack);
             unset($this->taskInfo[$fd]);
             return true;
     }
     return true;
 }
开发者ID:similarJ,项目名称:Dora-RPC,代码行数:82,代码来源:server.php

示例8: 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") {
        $task_id = $serv->task("task " . $fd);
        echo "Dispath AsyncTask: id={$task_id}\n";
    } elseif ($cmd == "taskclose") {
        $serv->task("close " . $fd);
        echo "close the connection in taskworker\n";
    } elseif ($cmd == "tasksend") {
        $serv->task("send " . $fd);
    } elseif ($cmd == "bigtask") {
        $serv->task(str_repeat('A', 8192 * 5));
    } elseif ($cmd == "taskwait") {
        $result = $serv->taskwait("taskwait");
        if ($result) {
            $serv->send($fd, "taskwaitok");
        }
        echo "SyncTask: result=" . var_export($result, true) . "\n";
    } elseif ($cmd == "taskWaitMulti") {
        $result = $serv->taskWaitMulti(array(str_repeat('A', 8192 * 5), str_repeat('B', 8192 * 6), str_repeat('C', 8192 * 8)));
        if ($result) {
            $resp = "taskWaitMulti ok\n";
            foreach ($result as $k => $v) {
                $resp .= "result[{$k}] length=" . strlen($v) . "\n";
            }
            $serv->send($fd, $resp);
        } else {
            $serv->send($fd, "taskWaitMulti error\n");
        }
    } elseif ($cmd == "hellotask") {
        $serv->task("hellotask");
    } elseif ($cmd == "taskcallback") {
        $serv->task("taskcallback", -1, function (swoole_server $serv, $task_id, $data) {
            echo "Task Callback: ";
            var_dump($task_id, $data);
        });
    } elseif ($cmd == "sendto") {
        $serv->sendto("127.0.0.1", 9999, "hello world");
    } elseif ($cmd == "close") {
        $serv->send($fd, "close connection\n");
        $result = $serv->close($fd);
    } elseif ($cmd == "info") {
        $info = $serv->connection_info(strval($fd), $from_id);
        var_dump($info["remote_ip"]);
        $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
    } elseif ($cmd == 'proxy') {
        $serv->send(1, "hello world\n");
    } elseif ($cmd == 'sleep') {
        sleep(10);
    } elseif ($cmd == 'foreach') {
        foreach ($serv->connections as $fd) {
            echo "conn : {$fd}\n";
        }
        return;
    } elseif ($cmd == 'tick') {
        $serv->tick(2000, function ($id) {
            echo "tick #{$id}\n";
        });
    } elseif ($cmd == 'addtimer') {
        $serv->addtimer(3000);
    } 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 ($cmd == 'pause') {
        echo "pause receive data. fd={$fd}\n";
        $serv->pause($fd);
    } elseif (substr($cmd, 0, 6) == "resume") {
        $resume_fd = substr($cmd, 7);
        $serv->resume($resume_fd);
    } elseif (substr($cmd, 0, 5) == "close") {
        $close_fd = substr($cmd, 6);
        $serv->close($close_fd);
    } elseif ($cmd == "shutdown") {
        $serv->shutdown();
//.........这里部分代码省略.........
开发者ID:google2013,项目名称:swoole-src,代码行数:101,代码来源:server.php


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