?? ????? workerman Tutorial?? Workerman? ???? ???? ???? ??? ???????. ??? ????? ??? ?? ????!
Workerman? ???? PHP?? ??? ?? ?? ??? PHP ?? ?? ????????. ??? ?, ??? ??, WeChat ???, ??? ?? ??, ??? ??, PHP ???, ???? ??, ??? ?, ?? ???, ?? ??? ? ?? ??? ??? ?? ?????.
TCP ? ??? ???? Websocket, HTTP ? ?? ????? ???? ??? ?? ????? ?????. ??? Mysql, ??? Redis, ??? Http, ??? ??? ??? ?? ?? ?? ??? ?? ??? ????. ??? ???? swoole? MeepoPS? ????.
?? Workererman? ? ??? ?? ??? web-msg-sender? ???????.
# wget http://www.workerman.net/download/senderzip # unzip senderzip #cd web-msg-sender #vim start.php
use Workerman\Worker; // composer 的 autoload 文件 include __DIR__ . '/vendor/autoload.php'; if(strpos(strtolower(PHP_OS), 'win') === 0) { exit("start.php not support windows, please use start_for_win.bat\n"); } // 標記是全局啟動 define('GLOBAL_START', 1); // 加載IO 和 Web require_once __DIR__ . '/start_io.php'; 可以注釋掉 webServer 服務 沒什么用 省點資源 // require_once __DIR__ . '/start_web.php'; // 運行所有服務 Worker::runAll();
Save
#vim start_io.php 找到 將端口改成你要監(jiān)聽的端口 我是2120 記住要在安全組里入方向添加白名單 // PHPSocketIO服務 $sender_io = new SocketIO(2120); 服務端設置完畢后 #php start.php start -d //開啟服務 并保持進程
Push ??? ?? tp5? ?????
<?php namespace app\index\moudel; /** * 推送事件 * 典型調用方式: * $push = new WebSocket(); * $push->setUser($user_id)->setContent($string)->push();//連貫操作 * * Class WebSocket * @package app\index\moudel; */ class WebSocket { /** * @var string 目標用戶id */ protected $to_user = ''; /** * @var string 推送服務地址 */ protected $push_api_url = 'http://127.0.0.1:2000'; /** * @var string 推送內容 */ protected $content = ''; /** * 設置推送用戶,若參數(shù)留空則推送到所有在線用戶 * * @param string $user * @return $this */ public function setUser($user = '') { $this->to_user = $user ? : ''; return $this; } /** * 設置推送內容 * * @param string $content * @return $this */ public function setContent($content = '') { $this->content = $content; return $this; } /** * 推送 */ public function push() { $data = [ 'type' => 'publish', 'content' => $this->content, 'to' => $this->to_user, ]; // var_dump($data); // var_dump($this->push_api_url); $ch = curl_init (); curl_setopt($ch, CURLOPT_URL, $this->push_api_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); $res = curl_exec($ch); curl_close($ch); dump($res); } }
?? ????
<?php namespace app\index\controller; use think\Controller; use app\index\moudel\WebSocket; class Index extends Controller { /** * 推送一個字符串 */ public function push_msg(){ $uid = input('uid','');//uid為空的時候推送給所有用戶 $string = '這是一個推送的測試'; $string = input('msg') ? : $string; $push = new WebSocket(); $push->setUser($uid)->setContent($string)->push(); } /** * 推送目標頁 * * @return \think\response\View */ public function targetPage(){ return view(); } }
?? ??? ????? ??
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <strong id="count"></strong> <h1 id="target"></h1> </body> </html> <script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script> <script src='http://cdn.bootcss.com/socket.io/1.3.7/socket.io.js'></script> <script> jQuery(function ($) { // 連接服務端 var socket = io('http://39.106.132.216:2000/'); //這里當然填寫真實的地址了 // uid可以是自己網站的用戶id,以便針對uid推送以及統(tǒng)計在線人數(shù),但一定是唯一標識 uid = 321; // socket連接后以uid登錄 socket.on('connect', function () { socket.emit('login', uid); }); // 后端推送來消息時 socket.on('new_msg', function (msg) { console.log("收到消息:" + msg); $('#target').append(msg).append('<br>'); }); // 后端推送來在線數(shù)據時 socket.on('update_online_count', function (online_stat) { console.log(online_stat); $('#count').html(online_stat); }); }) </script>
http://我自己的域名/index/index/pushAString?uid=123 ok 為推送成功 offline 為未在線 fail 為失敗
????? ?? ?? 321? ? ??? UID???
? ??? ??? ??? Workererman? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Workerman ???? ?? ??? ? ????? ????? ?? ?? ??? ?????. ??: Workerman? ???? ????? ???? ?? ??? PHP ??? ???? ?? ????????. ?? ???? ?? ??? ? ????? ???? ?? ?? ?????. ? ????? Workerman ?????? ???? ?? ??? ? ????? ???? ??? ???? ???? ?? ??? ?????. 1. ?? ???: ?? ???? ?? ???? ?? ??? ??? ???? ??? ????. ??? ?????

Swoole? Workerman? ?? ??? PHP ?? ????????. ??? ??, ??? ?? ? ????? ? ??? Swoole? ?? ?? ?? ??? ?? ???? ???? ?? ????? ?????. Workerman? ?? ???? ?? ??? ??? ???? ????? ? ??? ???? API? ?? ???? ? ??? ??? ???? ?????.

Workerman ??? ?? ???? ???? ?? ??: Workerman? ???? ???? ?? ???? ??????? ?? ???? ? ??? ?? ??? PHP ?? ????????. ? ????? ?? ? ??, ??? ? ?? ?? ??, ????? ?? ?? ? Workerman? ?? ???? ?????. ??? ?? ?? ??? ??????. 1. Workerman? ???? ????? ???? ?? ??? ?????.

Workerman ???? ??? ??? ???? ?? Workerman? ??? ??? ??? ??? ??? ???? ??? PHP ??? ???? ?? ????????. ???? ???? ??? ?? ?? ??? ??? ?????. ?? ??? ?? ? ??? ?? ?????? ????? ?? ?????. ????? Workerman?? ??? ??? ???? ??? ??? ???? ???? ?? ??? ???????. 1??: Workerman ?? ?? Worker? ???? ???.

Workerman ??: UDP ???? ?? ??? ???? ??: ? ???? Workerman ?????? ???? UDP ???? ?? ??? ???? ??? ???? ??? ?????. UDP ????? ??? ????? ???? ?? ??? ?? ????? ??? ??? ?? ?? ??????? ???? ??? ?????. ??: ???? ???? ??? ????? ?? ??? ?????. ?? TCP ????? ??? ?? ?? ?? ? ?? ?? ?? ??? ??? ? ????. ??? UDP

Workerman ???? ??? ??? ??? ????? ???? ?? ??? ?????. ??: Workerman? ??? ??? ??? ??? ???? ??? PHP ?? ???? ???? ?? ?????? ? ??? ?? ? ?? ??? ?? ?????. ??. ? ? Workerman? ??? ?? ???? ??? ? ?? ???? ?? ??? ??? ??? ? ?? ??? ??? ??? ?????. ? ???? Workerman? ???? ??? ??? ??? ???? ??? ?????.

Workerman? ???? ???? ?? ??? ???? ????? ?? ?? ??? ?????. ?? ?? ????? ???? ??? ???? ?? ?? ? ?? ????? ??????? ?? ?? ?? ??? ???? ???. ????? ???? ???? ?? ?? ??? ???? ?? ?? ?? ? ??? ?????. ? ????? PHP ?? ?? ?????? Workerman? ???? ???? ?? ??? ???? ???? ??? ???? ???? ?? ??? ?????. 1. WorkermanWorke ??

Workerman? PHP? ???? ??? ??? ??? ??? ?? ?????? TCP/UDP ?????? ? ?? ??? ?? ??? ? ????. ?? Workerman? ??? ?? ??, ??? ?? ?? ?????? ??? ? ?? ?? ?? ?? ??? ?????. ? ???? Workerman?? ?? ?? ??? ???? ??? ???? ???? ?? ??? ?????. 1. ?? ??? ?? ?? ??? ??? ???? ???? ?????? ???? ??? ??? ??? ??, ??? ?? ????.
