WebSocket实战之————Workerman服务器的安装启动

安装php

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扩展(已经安装成功)

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

安装git

apt-get install git

下载 workerman-todpole

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

缺少官方依赖包,直接启动发现会报错:

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 的一个依赖管理工具(全局安装)

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

注意: 如果上诉命令因为权限执行失败, 请使用 sudo 再次尝试运行 mv 那行命令。

现在只需要运行 composer 命令就可以使用 Composer 而不需要输入 php composer.phar

vendor目录是依赖库的目录,这些其实都是可以通过一个命令来得到的,只要你提供composer.json文件,那么你将这个项目git clone下来之后,直接:

composer install

就可以得到相应的依赖库了。

再次启动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 多少个请求

posted @ 2017-11-13 23:50  jiangxiaobo  阅读(1030)  评论(2编辑  收藏  举报