workerman startup failure
Phenomenon 1
After starting, an error similar to the following appears:
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
Keyword: Address already in use
Fundamental cause: The port is occupied, preventing startup.
Solution 1
You can use the command netstat -anp | grep PORT_NUMBER to find out which program is occupying the port.
Then stop the corresponding program to free the port.
Solution 2
If you cannot stop the program using the corresponding port, you can resolve the issue by changing the port of Workerman.
Solution 3
If the port occupied by Workerman cannot be stopped using the stop command (usually due to a missing pid file or the main process being killed by the developer), you can kill the Workerman process by running the following two commands.
killall php
ps aux|grep -i workerman|awk '{print $2}'|xargs kill -9
Solution 4
If there are indeed no programs listening on this port, it may be that the developer has set up two or more listeners in Workerman with the same port. Please check the startup script to see if it is listening on the same port.
Solution 5
Check whether the program has enabled reusePort; try disabling reusePort.
Phenomenon 2
After starting, an error similar to the following appears:
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
or
PHP Warning: stream_socket_server(): unable to connect to tcp://xx.xx.xx.xx:xxxx (在其上下文中,该请求的地址无效) in ...workerman/Worker.php on line xxxx
Keywords: Cannot assign requested address or 该请求的地址无效
Failure cause:
The IP parameter in the startup script is incorrect and not the local IP. Please enter the local IP or use 0.0.0.0 (which means listening on all local IPs) to resolve the issue.
Tip: On Linux systems, you can use the command ifconfig to view all network card IPs on the machine.
If you are a cloud server user (Alibaba Cloud/Tencent Cloud, etc.), note that your public IP may actually be a proxy IP (e.g., Alibaba Cloud's VPC), and the public IP does not belong to the current server, so you cannot listen via the public IP. However, you can still bind using 0.0.0.0.
Phenomenon 3
Warning stream_socket_server has been disabled for security reasons in ...
Failure cause:
The stream_socket_server function is disabled in php.ini.
Solution
-
Run
php --inito find the php.ini file. -
Open php.ini and find the
disable_functionsoption, then removestream_socket_serverfrom the disabled functions.
Phenomenon 4
PHP Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0:xxx (Permission denied)
Failure cause
On Linux, listening on ports below 1024 requires root privileges.
Solution
Use a port greater than 1024 or start the service using the root user.