色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

使用swoole擴展php websocket示例

復制代碼 代碼如下:
<?php
define('DEBUG', 'on');
define("WEBPATH", str_replace("http://","/", __DIR__));
require __DIR__ . '/../libs/lib_config.php';

class WebSocket extends Swoole/NETwork/Protocol/WebSocket
{
    /**
     * 下線時,通知所有人
     */
    function onClose($serv, $client_id, $from_id)
    {
        //將下線消息發送給所有人
        //$this->log("onOffline: " . $client_id);
        //$this->broadcast($client_id, "onOffline: " . $client_id);
        parent::onClose($serv, $client_id, $from_id);
    }

    /**
     * 接收到消息時
     * @see WSProtocol::onMessage()
     */
    function onMessage($client_id, $ws)
    {
        $this->log("onMessage: ".$client_id.' = '.$ws['message']);
        $this->send($client_id, "Server: ".$ws['message']);
  //$this->broadcast($client_id, $ws['message']);
    }

    function broadcast($client_id, $msg)
    {
        foreach ($this->connections as $clid => $info)
        {
            if ($client_id != $clid)
            {
                $this->send($clid, $msg);
            }
        }
    }
}


$AppSvr = new WebSocket();
$AppSvr->loadSetting(__DIR__."/swoole.ini"); //加載配置文件
$AppSvr->setLogger(new /Swoole/Log/EchoLog(true)); //Logger

$server = new /Swoole/NETwork/Server('0.0.0.0', 9503);
$server->setProtocol($AppSvr);
//$server->daemonize(); //作為守護進程
$server->run(array('worker_num' =>4));

php技術使用swoole擴展php websocket示例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 沭阳县| 图们市| 聂荣县| 清河县| 安阳县| 玛纳斯县| 浦县| 石河子市| 嘉定区| 舟山市| 绍兴县| 陵水| 邹平县| 搜索| 福州市| 保定市| 瑞安市| 桐庐县| 紫金县| 中卫市| 周口市| 政和县| 瓦房店市| 临邑县| 昌乐县| 廊坊市| 阿巴嘎旗| 呼和浩特市| 荥阳市| 敦化市| 杂多县| 天等县| 平遥县| 久治县| 嘉兴市| 汝阳县| 富宁县| 镇坪县| 鹿泉市| 诏安县| 南乐县|