Swoole 結合TP5搭建文字直播平台

2022-08-21 07:30:17 字數 2697 閱讀 1281

直播模組流程:

主程序服務:主程序同時開啟兩個服務

在專案根目錄(框架**同級目錄)建立script目錄,用於存放指令碼檔案

ws.php : 主程序服務

* time: 上午12:50 */

//執行應用並響應

try

catch (\exception

$e)

$res = ob_get_contents

();

ob_end_clean

();

$response->end($res

); }

/*** @param $serv

* @param $taskid

* @param $workerid

* @param $data

*/public

function ontask($serv, $taskid, $workerid, $data

) /**

* @param $serv

* @param $taskid

* @param $data

*/public

function onfinish($serv, $taskid, $data

) \n";

echo "finish-data-sucess:\n";

}/**

* 監聽ws連線事件

* @param $ws

* @param $request

*/public

function onopen($ws, $request

) /**

* 監聽ws訊息事件

* @param $ws

* @param $frame

*/public

function onmessage($ws, $frame

) \n";

$ws->push($frame->fd, "server-push:" . date("y-m-d h:i:s"));

}/**

* close

* @param $ws

* @param $fd

*/public

function onclose($ws, $fd

) \n";

}/**

* 記錄日誌

*/public

function

writelog() ) }

new ws();

class

live

$data =[

//這裡獲取直播管理頁面傳遞過來的資料

];

//獲取連線的使用者

// 賽況的基本資訊入庫 2、資料組織好 push到直播頁面

$taskdata =[

'method' => 'pushlive',

'data' => $data

];

//task類中 pushlive 方法負責推送資料

//返回成功給管理頁面

return util::show(config('code.success'), 'ok');}}

class

task }}

搭建tp5隨記

基於nginx 在vhost的檔案中 server error page 404 404.html redirect server error pages to the static page 50x.html error page 500 502 503 504 50x.html location...

tp5使用UEditor富文字編輯器

tp5使用ueditor富文字編輯器 2.開啟 ueditor.config.js 找到 initialframewidth 800 初始化編輯器寬度,預設1000 initialframeheight 320 初始化編輯器高度,預設320 設定顯示大小 3.修改上傳路徑,應該 開啟 ueditor...

使用tp5框架整合 layui富文字編輯器

一睹芳容 css css目錄 modules 模組css目錄 一般如果模組相對較大,我們會單獨提取 laydate layer default layim skin font 字型圖示目錄 images 資源目錄 一些表情等 face lay js目錄 dest 經過合併的完整模組 modules ...