swoole安装基本配置
生活随笔
收集整理的這篇文章主要介紹了
swoole安装基本配置
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
php安裝swoole
1. 下載swoole安裝
``` wget http://pecl.php.net/get/swoole-1.9.1.tgz tar -zxvf swoole-1.9.1.tgz cd swoole-1.9.1 phpize ./configure make make install ```- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
2. 在php.ini添加swoole.so
``` extension=swoole.so ```- 1
- 2
- 3
- 4
3. php文件
``` <?php $server = new swoole_websocket_server("0.0.0.0", 9501);$server->on('open', function (swoole_websocket_server $server, $request) {echo "server: handshake success with fd{$request->fd}\n"; });$server->on('message', function (swoole_websocket_server $server, $frame) {echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";$server->push($frame->fd, "這是服務(wù)器消息!"); });$server->on('close', function ($ser, $fd) {echo "client {$fd} closed\n"; });$server->start(); ```- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
4. html文件
``` <!DOCTYPE html> <html> <head><title>歡迎使用swoole!</title> </head> <body> <script type="text/javascript">// 創(chuàng)建一個(gè)Socket實(shí)例var socket = new WebSocket('ws://192.168.1.127:9501/');// 打開Socketsocket.onopen = function(event) {// 發(fā)送一個(gè)初始化消息socket.send('我是客戶端并且正在監(jiān)聽。');// 監(jiān)聽消息socket.onmessage = function(event) {console.log('客戶端接收到一個(gè)消息。',event);};// 監(jiān)聽Socket的關(guān)閉socket.onclose = function(event) {console.log('客戶端通知套接字已關(guān)閉。',event);};// 關(guān)閉Socket....//socket.close()}; </script> <h1>歡迎使用swoole!</h1> </body> </html> ```- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
5. 打開防火墻9501端口
``` firewall-cmd --zone=public --add-port=9501/tcp --permanent systemctl restart firewalld ```- 1
- 2
- 3
- 4
- 5
6.. 啟動(dòng)swoole服務(wù)
``` php /usr/local/nginx-1.11.5/html/index.php ```來源:https://blog.csdn.net/aojianmo2012/article/details/55046571
總結(jié)
以上是生活随笔為你收集整理的swoole安装基本配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建WebSocket服务器
- 下一篇: 如何处理高并发情况下的DB插入