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


PHP swoole_server类代码示例

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


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

示例1: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    //var_dump($serv->connection_info($fd, $from_id));
    //echo "worker_pid=".posix_getpid().PHP_EOL;
    //var_dump($fd, $from_id);
    $serv->send($fd, 'Swoole: ' . $data, $from_id);
}
开发者ID:sophia2152,项目名称:swoole-src,代码行数:7,代码来源:udp.php

示例2: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message From Client {$fd}:{$data}\n";
     $this->test = new Test();
     var_dump($this->test);
     $serv->task(serialize($this->test));
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:7,代码来源:Server.php

示例3: my_onTask

function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
    static $datas = array();
    if (isset($data['cmd'])) {
        switch ($data['cmd']) {
            case 'get':
                $key = $data['key'];
                $val = isset($datas[$key]) ? $datas[$key] : "";
                $serv->finish(array('key' => $key, 'val' => $val));
                break;
            case "set":
                $key = $data['key'];
                $val = $data['val'] . "_" . $from_id;
                $datas[$key] = $val;
                return;
                break;
            case "del":
                $key = $data['key'];
                if (isset($datas[$key])) {
                    unset($datas[$key]);
                }
                break;
            case "task":
                $key = $data['key'];
                echo "Do task " . $key . PHP_EOL;
                break;
        }
    }
    echo "AsyncTask[PID=" . posix_getpid() . "]: task_id={$task_id}." . PHP_EOL;
    // $serv->finish("OK");
}
开发者ID:liangkwok,项目名称:Swoole,代码行数:31,代码来源:shared_server.php

示例4: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message from client {$fd}:{$data}:{$from_id}\n";
     $params = array('fd' => $fd, 'file' => $data);
     $id = $serv->task(json_encode($params));
     echo "Continue Handle Worker {$id}\n";
 }
开发者ID:shijl,项目名称:swoole,代码行数:7,代码来源:server.php

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

示例6: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    $cmd = trim($data);
    if ($cmd == "reload") {
        $serv->reload($serv);
    } elseif ($cmd == "task") {
        $task_id = $serv->task("hello world", 0);
        echo "Dispath AsyncTask: id={$task_id}\n";
    } elseif ($cmd == "info") {
        $info = $serv->connection_info($fd);
        $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
    } elseif ($cmd == "broadcast") {
        $start_fd = 0;
        while (true) {
            $conn_list = $serv->connection_list($start_fd, 10);
            if ($conn_list === false) {
                break;
            }
            $start_fd = end($conn_list);
            foreach ($conn_list as $conn) {
                if ($conn === $fd) {
                    continue;
                }
                $serv->send($conn, "hello from {$fd}\n");
            }
        }
    } elseif ($cmd == "error") {
        hello_no_exists();
    } elseif ($cmd == "shutdown") {
        $serv->shutdown();
    } else {
        $serv->send($fd, 'Server Receive: ' . $data . PHP_EOL, $from_id);
        $data = json_decode($data, true);
        if (isset($data['cmd'])) {
            switch ($data['cmd']) {
                case 'get':
                    $key = $data['key'];
                    $result = $serv->taskwait(json_encode($data), 0.5, 0);
                    $serv->send($fd, "get {$key}:" . $result . PHP_EOL);
                    break;
                case "set":
                    $serv->task(json_encode($data), 0);
                    $serv->send($fd, "ok" . PHP_EOL);
                    break;
                case "del":
                    $serv->task(json_encode($data), 0);
                    break;
                case "reload":
                    break;
                default:
                    echo "server:" . $data . PHP_EOL;
            }
        }
        //$serv->close($fd);
    }
    //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data";
    //$serv->deltimer(800);
    //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id);
}
开发者ID:xxoxx,项目名称:gitswoolestudy,代码行数:59,代码来源:task_shared_serv.php

示例7: process

 public function process(swoole_server $serv, $taskId, $fromId, $data)
 {
     // model load
     $this->defaultModel->sayHello();
     // library load
     $this->mcurl->isEnable();
     $serv->finish('sync ok!');
 }
开发者ID:ErosZy,项目名称:CSF,代码行数:8,代码来源:SyncTask.php

示例8: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message From Client {$fd}:{$data}\n";
     // send a task to task worker.
     $param = array('fd' => $fd, 'source' => $data);
     $serv->task(json_encode($param));
     echo "Continue Handle Worker\n";
 }
开发者ID:CptSteven,项目名称:faster-rcnn-mod,代码行数:8,代码来源:train.php

示例9: serve

 function serve()
 {
     $serv = new \swoole_server(SERVERHOST, SERVERPORT);
     $serv->on('workerStart', [$this, 'onStart']);
     $serv->on('receive', [$this, 'onReceive']);
     $serv->set(array('worker_num' => 1, 'dispatch_mode' => 1, 'open_length_check' => true, 'package_max_length' => 8192000, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_body_offset' => 4));
     $serv->start();
 }
开发者ID:qieangel2013,项目名称:zys,代码行数:8,代码来源:RpcServer.php

示例10: __construct

 public function __construct($host, $ip, $config, $bufferDriverClass)
 {
     $server = new \swoole_server($host, $ip, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
     $server->set($config);
     $server->on('receive', array($this, 'onReceive'));
     $server->on('close', array($this, 'onClose'));
     $this->server =& $server;
     $this->bufferDriverClass = $bufferDriverClass;
 }
开发者ID:ehovel,项目名称:fatty,代码行数:9,代码来源:SwooleServer.php

示例11: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     $info = $serv->connection_info($fd, $from_id);
     if ($info['server_port'] == 9502) {
         $serv->send($fd, "welcom Admin \n");
     } else {
         $serv->send($fd, 'Swoole:' . $data);
     }
 }
开发者ID:alenslan,项目名称:nanshan,代码行数:9,代码来源:multi_port.php

示例12: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message From Client {$fd}:{$data}\n";
     foreach ($serv->connections as $client) {
         if ($fd != $client) {
             $serv->send($client, $data);
         }
     }
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:9,代码来源:chat_server.php

示例13: onConnect

 public function onConnect(swoole_server $serv, $fd, $from_id)
 {
     //获取连接的客户端信息
     $fdInfo = $serv->connection_info($fd);
     echo '<pre>';
     print_r($fdInfo);
     echo '</pre>';
     $serv->send($fd, "Welcome {$fd} Connect Server");
 }
开发者ID:stonegithubs,项目名称:swoole-game,代码行数:9,代码来源:server.php

示例14: run

 function run()
 {
     $serv = new swoole_server("127.0.0.1", 8002);
     $serv->set(array('timeout' => 1, 'poll_thread_num' => 1, 'worker_num' => 1, 'backlog' => 128, 'max_conn' => 10000, 'dispatch_mode' => 2));
     $serv->on('Receive', array($this, 'onReceive'));
     $serv->on('Close', array($this, 'onClose'));
     //swoole_server_addtimer($serv, 2);
     #swoole_server_addtimer($serv, 10);
     $serv->start();
 }
开发者ID:jinguanio,项目名称:david,代码行数:10,代码来源:serv.php

示例15: onReceive

 function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     $this->count[$fd]++;
     echo "Client#{$fd} recv: {$data}\n";
     if ($this->count[$fd] > 10) {
         $serv->close($fd);
     } else {
         $serv->send($fd, "hello client");
     }
 }
开发者ID:sophia2152,项目名称:swoole-src,代码行数:10,代码来源:reconnect_server.php


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