workerman問題總結大全及解決方案

u=2585961696,2932252169&fm=11&gp=0.jpg

workerman沒法正常訪問

問題描述:在阿里雲ECS上部署了workerman的應用(ECS是專有網絡),在ECS安全組裏已經容許workerman須要的所有端口,可是外網一直不能正常打開(注,其餘服務,比80端口外部是能夠用訪問的)。telnet鏈接顯示「No route to host」,並且我是關閉了centos7的firewalld防火牆的,這讓我很困惑。php

問題緣由:linux

由於對centos7瞭解很少,關閉firewalld.service後,並無關閉iptable.service致使的。vim

解決問題:windows

一、安全組入方向,設置workerman 的端口範圍;centos

二、關閉firewalld防火牆和修改/etc/sysconfig/iptables規則。安全

workerman 不能關閉怎麼辦

問題描述:啓動腳本里執行Worker::stopAll()並不能中止workerman,Worker::stopAll()只有在運行workerman的主進程裏執行纔有效,外部其它進程執行沒有效果。服務器

中止Workerman的流程是網絡

一、找到Workerman主進程pidphp7

二、給pid發送SIGINT信號(posix_kill(SIGINT, pid))app

三、workerman主進程收到SIGINT信號後自身執行Worker::stopAll()完成服務中止。

這三個步驟workerman內部應封裝好,調用流程是

一、設置$argv = 'stop';

二、運行Worker::runAll();

workerman沒法使用怎麼辦

問題描述:啓動後報錯相似以下:php start.php start

PHP Warning: stream_socket_server(): unable to connect to tcp://xx.xx.xx.xx:xxxx (Address already in use) in ...workerman/Worker.php on line xxxx

關鍵字: Address already in use

失敗緣由:

端口被佔用,沒法啓動。

能夠經過命令netstat -anp | grep 端口號來找出哪一個程序佔用了端口。 而後中止對應的程序釋放端口解決。

若是不能中止對應端口的程序,能夠經過更換workerman的端口解決。

若是是Workerman佔用的端口,又沒法經過stop命令中止(通常是丟失pid文件或者主進程被開發者kill了致使),能夠經過運行如下兩個命令殺死Workerman進程。killall php

ps aux|grep WorkerMan|awk '{print $2}'|xargs kill -9

若是確實沒有程序監聽這個端口,那麼多是開發者在workerman裏設置了兩個或兩個以上的監聽,而且監聽的端口相同致使,請開發者自行檢查啓動腳本是否監聽了相同的端口。現象2

啓動後報錯相似以下:PHP Warning: stream_socket_server(): unable to connect to tcp://xx.xx.xx.xx:xxx (Cannot assign requested address) in ...workerman/Worker.php on line xxxx

或者PHP Warning: stream_socket_server(): unable to connect to tcp://xx.xx.xx.xx:xxxx (在其上下文中,該請求的地址無效) in ...workerman/Worker.php on line xxxx

關鍵字: Cannot assign requested address或者該請求的地址無效

失敗緣由:

啓動腳本監聽ip參數寫錯,不是本機ip,請填寫本機ip機或者填寫 0.0.0.0(表示監聽本機全部ip)便可解決。

提示:Linux系統能夠經過命令 ifconfig查看本機全部網卡ip。

若是您是雲服務器(阿里雲/騰訊雲等)用戶,注意您的公網ip實際多是個代理ip(例如阿里雲的專有網絡),公網ip並不屬於當前的服務器,因此沒法經過公網ip監聽。雖然不能用公網ip監聽,可是仍然能夠經過0.0.0.0來綁定。現象3Waring stream_socket_server has been disabled for security reasons in ...

失敗緣由:

stream_socket_server 函數被php.ini禁用

解決方法

一、運行php --ini 找到php.ini文件

二、打開php.ini找到disable_functions一項,將stream_socket_server禁用項刪掉現象4PHP Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0:xxx (Permission denied)

失敗緣由

linux下監聽端口若是小於1024,須要root權限。

解決辦法

使用大於1024的端口或者使用root用戶啓動服務。

workerman能夠一直運行麼

workerman能夠一直運行,以daemon(守護進程)方式啓動workerman便可後臺一直運行。

啓動中止workerman:

啓動

以debug(調試)方式啓動
php start.php start

以daemon(守護進程)方式啓動
php start.php start -d

中止
php start.php stop

重啓
php start.php restart

平滑重啓
php start.php reload

查看狀態
php start.php status

debug和daemon方式區別:

一、以debug方式啓動,代碼中echo、var_dump、print等打印函數會直接輸出在終端。

二、以daemon方式啓動,代碼中echo、var_dump、print等打印會默認重定向到/dev/null文件,能夠經過設置Worker::$stdoutFile = '/your/path/file';來設置這個文件路徑。

三、以debug方式啓動,終端關閉後workerman會隨之關閉並退出。

四、以daemon方式啓動,終端關閉後workerman繼續後臺正常運行

workerman沒法socket怎麼辦

Workerman是一款純PHP開發的開源高性能的PHP socket 服務器框架。被普遍的用於手機app、手遊服務端、網絡遊戲服務器、聊天室服務器、硬件通信服務器、智能家居、車聯網、物聯網等領域的開發。可是在配置workerman狀況下,難免有些意想不到的錯誤,下面小編整理網上資料並整合自身遇到的問題,給出如下幾種經常使用的解決方案。

問題描述:

現象1

啓動後報錯相似以下:
php start.php start
PHP Warning:  stream\_socket\_server(): unable to connect to tcp://xx.xx.xx.xx:xxxx (Address already in use) in /home/workerman-chat/Workerman/Worker.php on line xxxx

關鍵字: Address already in use

失敗緣由:端口被佔用,沒法啓動。

能夠經過命令netstat -anp | grep 端口號來找出哪一個程序佔用了端口。

而後中止對應的程序釋放端口解決。

若是不能中止對應端口的程序,能夠經過更換workerman的端口解決。

若是是Workerman佔用的端口,又沒法經過stop命令中止(通常是丟失pid文件或者主進程被開發者kill了致使),能夠經過運行如下兩個命令殺死Workerman進程。
`killall php

ps aux|grep WorkerMan|awk '{print $2}'|xargs kill -9`

現象2

啓動後報錯相似以下:

PHP Warning:  stream\_socket\_server(): unable to connect to tcp://xx.xx.xx.xx:xxx (Cannot assign requested address) in /home/GatewayWorker/Workerman/Worker.php on line xxxx

關鍵字:Cannot assign requested address

失敗緣由:

啓動腳本ip參數寫錯,不是本機ip,請填寫本機ip機或者填寫 0.0.0.0(表示監聽本機全部ip)便可解決。

提示:Linux系統能夠經過命令 ifconfig查看本機全部網卡ip。

若是您是騰訊雲用戶,注意您的公網ip實際是代理服務器ip,公網ip並不屬於你的服務器,因此沒法經過公網ip綁定,可是能夠經過0.0.0.0來綁定。

現象3

啓動後報錯相似以下:

Waring stream\_socket\_server has been disabled **for**security reasons in ...

失敗緣由:

stream_socket_server 函數被php.ini禁用

解決方法

一、運行php --ini 找到php.ini文件

二、打開php.ini找到disable_functions一項,將stream_socket_server禁用項刪掉

現象4

啓動後報錯相似以下:
PHP Warning:  stream\_socket\_server(): unable to connect to tcp://0.0.0.0:xxx (Permission denied)

失敗緣由

linux下監聽端口若是小於1024,須要root權限。

解決辦法

使用大於1024的端口或者使用root用戶啓動服務。

現象5

啓動後報錯相似以下:
WebSocket connection to 'ws://x.x.x.x:2346/'failed: Error in connection establishment:net::ERR\_NAME\_NOT\_TIMED\_OUT

失敗緣由

服務器防火牆擋住了設置的端口,這裏於2346爲例。

解決辦法

進入Linux vim編輯服務器防火牆文件,添加你須要開發的服務器端口保存後重啓防火牆。

[root@iZwz9xxxxxxxxxxxxxxxxxx conf]# iptables -nvl #查看容許訪問的端口

[root@iZwz9xxxxxxxxxxxxxxxxxx conf]# vim /etc/sysconfig/iptables #編輯

[root@iZwz9xxxxxxxxxxxxxxxxxx conf]# /etc/init.d/iptables restart #重啓

workerman沒法監聽怎麼辦

問題描述:根據手冊一步一步走下來,可是發如今啓動監聽的時候,發生了錯誤:
\[think\\exception\\ThrowableError\]

Fatal error: Call to undefined **function**Workerman\\Lib\\pcntl\_signal()

本地運行環境:win10+php7,已經用composer下載了workerman-for-win了

解決辦法:

若是是在windows下面composer安裝的話,在文檔第一步
composer **require**topthink/think-worker

的時候,它還會順帶下載workerman/workerman,可是由於是在windows下面運行,因此要刪除掉workerman/workerman,再進行下一步。
workerman/workerman-**for**\-win
這時,你再啓動監聽就能夠了!

好了,關於workerman的問題和解決方案到此了,下次再跟你們分享。

相關文章
相關標籤/搜索