最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用swoole擴展php websocket示例

 更新時間:2014年02月13日 09:03:49   作者:  
WebSocket規(guī)范的目標是在瀏覽器中實現(xiàn)和服務器端雙向通信。雙向通信可以拓展瀏覽器上的應用類型,如果你想要用PHP來寫websocket應用,那swoole_framework一定是最好的選擇,需要的朋友可以參考下

復制代碼 代碼如下:

<?php
define('DEBUG', 'on');
define("WEBPATH", str_replace("\\","/", __DIR__));
require __DIR__ . '/../libs/lib_config.php';

class WebSocket extends Swoole\Network\Protocol\WebSocket
{
    /**
     * 下線時,通知所有人
     */
    function onClose($serv, $client_id, $from_id)
    {
        //將下線消息發(fā)送給所有人
        //$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));

相關文章

最新評論

胶南市| 麟游县| 铁岭县| 南宁市| 兴山县| 新巴尔虎左旗| 民勤县| 黑水县| 竹山县| 建瓯市| 清原| 普兰县| 鄢陵县| 林口县| 新竹县| 清丰县| 海兴县| 咸宁市| 射阳县| 江津市| 微山县| 土默特左旗| 嘉兴市| 马尔康县| 论坛| 清原| 卢龙县| 三台县| 林口县| 胶南市| 巢湖市| 长乐市| 宁都县| 青川县| 瑞丽市| 社会| 汽车| 陇南市| 东城区| 聂拉木县| 庄河市|