WebSocket實戰之————Workerman服務器的安裝啓動

安裝phpphp

apt-get install php5-cli
root@iZ23b64pe35Z:/home/www# php -v
PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct  3 2016 13:00:37) 

 檢查pcntl、posix擴展(已經安裝成功)git

root@iZ23b64pe35Z:/home/www# php -m | grep pcntl
pcntl
root@iZ23b64pe35Z:/home/www# php -m | grep posix
posix

安裝gitgithub

apt-get install git

下載 workerman-todpoleweb

git clone https://github.com/walkor/workerman-todpole.git

缺乏官方依賴包,直接啓動發現會報錯:json

複製代碼
root@iZ23b64pe35Z:/home/www# cd workerman-todpole/
root@iZ23b64pe35Z:/home/www/workerman-todpole# ls
Applications  composer.json  MIT-LICENSE.txt  README.md  start.php
root@iZ23b64pe35Z:/home/www/workerman-todpole# php start.php start
PHP Warning:  require_once(/home/www/workerman-todpole/vendor/autoload.php): failed to open stream: 
No such file or directory in /home/www/workerman-todpole/start.php on line 29
複製代碼

 安裝:Composer 是 PHP 的一個依賴管理工具(全局安裝)ubuntu

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

注意: 若是上訴命令由於權限執行失敗, 請使用 sudo 再次嘗試運行 mv 那行命令。瀏覽器

如今只須要運行 composer 命令就可使用 Composer 而不須要輸入 php composer.pharwebsocket

vendor目錄是依賴庫的目錄,這些其實都是能夠經過一個命令來獲得的,只要你提供composer.json文件,那麼你將這個項目git clone下來以後,直接:併發

composer install

就能夠獲得相應的依賴庫了。composer

再次啓動workerman

root@iZ23uv7rgv9Z:/home/www/workerman-todpole# ls
Applications  composer.json  composer.lock  MIT-LICENSE.txt  README.md  start.php  vendor

啓動正常

複製代碼
root@iZ23uv7rgv9Z:/home/www/workerman-todpole# php start.php start
Workerman[start.php] start in DEBUG mode
----------------------- WORKERMAN -----------------------------
Workerman version:3.3.6          PHP version:5.5.9-1ubuntu4.20
------------------------ WORKERS -------------------------------
user          worker                 listen                    processes status
root          TodpoleBusinessWorker  none                       4         [OK] 
root          TodpoleGateway         websocket://0.0.0.0:8282   4         [OK] 
root          Register               text://0.0.0.0:1237        1         [OK] 
root          WebServer              http://0.0.0.0:8383        2         [OK] 
----------------------------------------------------------------
Press Ctrl-C to quit. Start success.
複製代碼

查看本機的IP地址:

ip addr

再次啓動workerman,在瀏覽器地址輸入

http://本機IP地址:8383/

測試結果:

成功安裝!

狀態詳解

複製代碼
root@iZ23uv7rgv9Z:/home/www/workerman-todpole# php start.php status
Workerman[start.php] status 
---------------------------------------GLOBAL STATUS--------------------------------------------
Workerman version:3.3.6          PHP version:5.5.9-1ubuntu4.20
start time:2016-12-22 22:53:51   run 0 days 0 hours   
load average: 0, 0.01, 0.05      event-loop:select(libevent擴展(或者event擴展)使得PHP可使用系統Epoll、Kqueue等高級事件處理機制,可以顯著提升WorkerMan在高併發鏈接時CPU利用率。在高併發長鏈接相關應用中很是重要。libevent擴展(或者event擴展)不是必須的,若是沒安裝,則默認使用PHP原生Select事件處理機制。)
4 workers       11 processes
worker_name           exit_status     exit_count
TodpoleBusinessWorker 0                0
TodpoleGateway        0                0
Register              0                0
WebServer             0                0
---------------------------------------PROCESS STATUS-------------------------------------------
pid    memory  listening                worker_name           connections total_request send_fail throw_exception
4190    1.25M   http://0.0.0.0:8383      WebServer             0           0              0         0              
4191    1.25M   http://0.0.0.0:8383      WebServer             0           0              0         0              
4189    1.5M    text://0.0.0.0:1237      Register              8           8              0         0              
4185    1.5M    websocket://0.0.0.0:8282 TodpoleGateway        5           4              0         0              
4186    1.5M    websocket://0.0.0.0:8282 TodpoleGateway        5           4              0         0              
4187    1.5M    websocket://0.0.0.0:8282 TodpoleGateway        5           4              0         0              
4188    1.5M    websocket://0.0.0.0:8282 TodpoleGateway        5           4              0         0              
4181    1.75M   none                     TodpoleBusinessWorker 5           3              0         0              
4183    1.75M   none                     TodpoleBusinessWorker 5           1              0         0              
4182    1.75M   none                     TodpoleBusinessWorker 5           1              0         0              
4184    1.75M   none                     TodpoleBusinessWorker 5           1              0         0              
root@iZ23uv7rgv9Z:/home/www/workerman-todpole#
複製代碼

紅色爲對應的4個worker

黃色爲每一個worker退出的次數和狀態

 例如執行一個:php start.php reload (reload命令的話)

TodpoleBusinessWorker 會退出,(啓動的時候會直接去鏈接TodpoleGateway內部端口,會創建起通信的,不會監聽端口的)

TodpoleGateway(維持客戶端鏈接,若是退出就會和客戶端斷開的,會監聽端口的)是不會退出的

WebServer 有兩個進程也會退出兩次

Register(維持TodpoleBusinessWorker 和TodpoleGateway之間進行通訊的)內部服務,沒有任何邏輯,因此也不會退出的

total_request 多少個請求

 

貴在堅持,相信本身.
相關文章
相關標籤/搜索