日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

swoole安装基本配置

發(fā)布時(shí)間:2024/9/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。