国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

使用swoole擴展php websocket示例

2024-05-04 23:21:14
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


<?php
define('DEBUG', 'on');
define("WEBPATH", str_replace("http://","http://www.survivalescaperooms.com/", __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));

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富蕴县| 临泉县| 广宁县| 庄浪县| 梓潼县| 乐山市| 建平县| 资中县| 泸水县| 清远市| 巫山县| 大化| 新竹县| 伊吾县| 古交市| 平遥县| 那曲县| 宁城县| 澳门| 龙里县| 绥中县| 琼海市| 沙田区| 三门峡市| 天镇县| 永和县| 江永县| 石棉县| 西宁市| 邛崃市| 万源市| 盐津县| 星子县| 平和县| 油尖旺区| 于都县| 隆安县| 都江堰市| 霍州市| 五大连池市| 黎城县|