phpsocket.io icon indicating copy to clipboard operation
phpsocket.io copied to clipboard

The script stops in the deamon mode

Open alikenski opened this issue 5 years ago • 26 comments

Hello everyone. I have some problem. Yesterday I have started script in the deamon mode. But today I have noticed that PHPSocket.io script is stopped and I should restart it. I need 24/7 working script because the project is in production. So how solve this problem?

alikenski avatar Apr 03 '19 04:04 alikenski

Have you tried setting it up using a simple systemd service?

tolew1 avatar Apr 03 '19 14:04 tolew1

Show the workerman.log .

walkor avatar Apr 04 '19 02:04 walkor

Show the workerman.log .

2019-04-01 16:39:36 pid:3886379 Workerman[server.php] start in DAEMON mode
2019-04-01 16:41:25 pid:3886918 Workerman[server.php] stop 
2019-04-01 16:41:25 pid:3886918 Workerman[server.php] is stopping ...
2019-04-01 16:41:25 pid:3886381 Workerman[server.php] stopping ...
2019-04-01 16:41:25 pid:3886381 Workerman[server.php] has been stopped
2019-04-01 16:41:25 pid:3886918 Workerman[server.php] stop success
2019-04-01 16:41:30 pid:3886926 Workerman[server.php] start in DAEMON mode
2019-04-01 16:43:17 pid:3887498 Workerman[server.php] stop 
2019-04-01 16:43:17 pid:3887498 Workerman[server.php] is stopping ...
2019-04-01 16:43:17 pid:3886928 Workerman[server.php] stopping ...
2019-04-01 16:43:17 pid:3886928 Workerman[server.php] has been stopped
2019-04-01 16:43:17 pid:3887498 Workerman[server.php] stop success
2019-04-01 16:43:41 pid:3887642 Workerman[server.php] start in DAEMON mode
2019-04-01 16:44:15 pid:3887765 Workerman[server.php] stop 
2019-04-01 16:44:15 pid:3887765 Workerman[server.php] is stopping ...
2019-04-01 16:44:15 pid:3887644 Workerman[server.php] stopping ...
2019-04-01 16:44:15 pid:3887644 Workerman[server.php] has been stopped
2019-04-01 16:44:15 pid:3887765 Workerman[server.php] stop success
2019-04-01 16:44:17 pid:3887784 Workerman[server.php] start in DAEMON mode
2019-04-02 09:07:59 pid:43506 Workerman[server.php] start in DAEMON mode
2019-04-02 11:02:23 pid:95048 Workerman[server.php] restart 
2019-04-02 11:02:23 pid:95048 Workerman[server.php] is stopping ...
2019-04-02 11:02:23 pid:43508 Workerman[server.php] stopping ...
2019-04-02 11:02:23 pid:43508 Workerman[server.php] has been stopped
2019-04-02 11:02:23 pid:95048 Workerman[server.php] stop success
2019-04-02 18:03:48 pid:291150 Workerman[server.php] restart 
2019-04-02 18:03:48 pid:291150 Workerman[server.php] is stopping ...
2019-04-02 18:03:48 pid:95050 Workerman[server.php] stopping ...
2019-04-02 18:03:48 pid:95050 Workerman[server.php] has been stopped
2019-04-02 18:03:48 pid:291150 Workerman[server.php] stop success
2019-04-02 18:03:50 pid:291150 Workerman[server.php] stopping ...
2019-04-02 18:03:50 pid:291150 Workerman[server.php] has been stopped
2019-04-02 18:03:55 pid:291184 Workerman[server.php] restart 
2019-04-02 18:03:55 pid:291184 Workerman[server.php] is stopping ...
2019-04-02 18:03:55 pid:291184 Workerman[server.php] stop success
2019-04-03 08:57:45 pid:638092 Workerman[server.php] restart 
2019-04-03 08:57:45 pid:638092 Workerman[server.php] is stopping ...
2019-04-03 08:57:45 pid:638092 Workerman[server.php] stop success
2019-04-03 09:14:15 pid:647088 Workerman[server.php] connections 
2019-04-04 08:58:52 pid:1223531 Workerman[server.php] restart 
2019-04-04 08:58:52 pid:1223531 Workerman[server.php] is stopping ...
2019-04-04 08:58:52 pid:1223531 Workerman[server.php] stop success

alikenski avatar Apr 04 '19 04:04 alikenski

Which command do you use when restart php server.php restart or php server.php restart -d?

Show the first line of result for command top pelase.

walkor avatar Apr 04 '19 04:04 walkor

Which command do you use when restart php server.php restart or php server.php restart -d?

Show the first line of result for command top pelase.

top - 09:10:57 up 213 days, 23:37, 0 users, load average: 0.34, 0.63, 0.56 Tasks: 17 total, 1 running, 16 sleeping, 0 stopped, 0 zombie Cpu(s): 0.6%us, 0.7%sy, 0.2%ni, 98.3%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 32020248k total, 31147672k used, 872576k free, 787768k buffers Swap: 8191996k total, 661932k used, 7530064k free, 25254256k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

911335 kanbanme 20 0 65880 18m 2256 S 0.0 0.1 0:00.29 perl 911338 kanbanme 20 0 25024 816 668 S 0.0 0.0 0:00.00 cagefs_enter.pr 911340 kanbanme 20 0 163m 5236 5232 S 0.0 0.0 0:00.40 cloudlinux-cli- 911386 kanbanme 20 0 839m 13m 13m S 0.0 0.0 0:00.56 npm 911430 kanbanme 20 0 652m 26m 13m S 0.0 0.1 0:03.35 node 1223533 kanbanme 20 0 341m 11m 2200 S 0.0 0.0 0:00.00 php 1223534 kanbanme 20 0 341m 11m 1860 S 0.0 0.0 0:00.00 php 1228310 kanbanme 20 0 115m 25m 3776 S 0.0 0.1 0:00.09 cpaneld - servi 1228311 kanbanme 20 0 114m 24m 3744 S 0.0 0.1 0:00.11 cpaneld - servi 1228315 kanbanme 20 0 113m 23m 3636 S 0.0 0.1 0:00.01 cpaneld - servi 1228316 kanbanme 20 0 117m 23m 3584 S 0.0 0.1 0:00.01 cpaneld - servi 1228317 kanbanme 20 0 113m 23m 3640 S 0.0 0.1 0:00.04 cpaneld - servi 1228325 kanbanme 20 0 120m 28m 4348 S 0.0 0.1 0:00.12 cpsrvd websocke 1228331 kanbanme 20 0 25024 824 676 S 0.0 0.0 0:00.00 cagefs_enter.pr 1228333 kanbanme 20 0 13900 4032 1380 S 0.0 0.0 0:00.04 bash 1228663 kanbanme 20 0 15048 1176 960 R 0.0 0.0 0:00.00 top 1470820 kanbanme 20 0 1666m 673m 12m S 0.0 2.2 0:56.61 PM2 v3.4.1: God

alikenski avatar Apr 04 '19 04:04 alikenski

php server.php restart -d

This command. The server shuts down when i use command restart -d and start -d

alikenski avatar Apr 04 '19 04:04 alikenski

Show the results of command php -v please.

walkor avatar Apr 04 '19 07:04 walkor

Show the results of command php -v please.

PHP 5.6.40 (cli) (built: Feb 10 2019 17:27:13)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies

alikenski avatar Apr 04 '19 07:04 alikenski

@walkor So what problem is here?

alikenski avatar Apr 05 '19 04:04 alikenski

But today I have noticed that PHPSocket.io script is stopped

How do you judge that the PHPSocket.io script is stopped? You mean the process gone away?

walkor avatar Apr 05 '19 10:04 walkor

@walkor Look i will explain the situation. Yesterday at 9:00 in the morning i started phpsocket.io as a deamon. command php server.php start -d

By the documentation script should work 24/7 without stopping.

But today in the morning at 8:50 i have noticed that phpsocket.io is stopped. Because in the browser console i saw socket.io.js:2925 GET http://[SERVER_IP]:3001/socket.io/?EIO=3&transport=polling&t=1554462163163-1 net::ERR_CONNECTION_REFUSED. I go to the server console and wrote the command php server.php status and see this:

Workerman[server.php] status
Workerman[server.php] not run

So, why phpsocket.io stops every night if started as a deamon?

alikenski avatar Apr 05 '19 11:04 alikenski

Run command nohup strace -ttp pid -o /tmp/strace.log &. Pid is the master pid of phpsocket.io which can be found by command ps auxf. Do not run restart or stop command until the problem happens again. Then show me the /tmp/strace.log.

walkor avatar Apr 05 '19 12:04 walkor

@walkor Good day my friend.

  1. I wrote command ps auxf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
609       754135  0.0  0.0 139816   784 ?        S    17:38   0:00 pure-ftpd (IDLE)
609       437370  0.0  0.0 139816   960 ?        S    09:00   0:00 pure-ftpd (IDLE)
609       761056  1.2  0.0 121824 27276 ?        S    17:51   0:00 cpsrvd websocket - Shell
609       761068  0.0  0.0  25024   820 pts/1    Ss   17:51   0:00  \_ /bin/cagefs_enter.proxied /bin/bash -l
609       761070  0.4  0.0  13900  4036 pts/1    S    17:51   0:00      \_ /bin/bash -l
609       761399  0.0  0.0  13080   944 pts/1    R+   17:51   0:00          \_ ps auxf
609       761045  0.1  0.0 109132 22176 ?        S    17:51   0:00 cpaneld - serving 95.58.37.82
609       435500  0.0  0.0 349600 11792 ?        S    08:56   0:00 WorkerMan: master process  start_file=/home/kanbanmediana/public_html/socket/server.php
609       435501  0.0  0.0 351500 14168 ?        S    08:56   0:16  \_ WorkerMan: worker process  PHPSocketIO socketIO://0.0.0.0:3001
609      1470820  0.0  0.8 1706624 275892 ?      Ssl  Mar28   1:01 PM2 v3.4.1: God Daemon (/home/kanbanmediana/.pm2)
609       911335  0.0  0.0  65880 19148 ?        S    Mar27   0:00 /usr/local/cpanel/3rdparty/bin/perl -x -- /usr/local/cpanel/base/3rdparty/cloudlinux/cloudlinux-selector.cgi
609       911338  0.0  0.0  25024   816 ?        S    Mar27   0:00  \_ /bin/cagefs_enter.proxied /usr/share/l.v.e-manager/utils/cloudlinux-cli-user.py --data=eyJ1c2VyX2luZm8iOnsibHZlLWlkIjoiNjA5IiwidX
609       911340  0.0  0.0 167124  5236 ?        S    Mar27   0:00      \_ /opt/alt/python27/bin/python2.7 /usr/share/l.v.e-manager/utils/cloudlinux-cli-user.py --data=eyJ1c2VyX2luZm8iOnsibHZlLWlkIjoi
609       911386  0.0  0.0 859368 14032 ?        Sl   Mar27   0:00          \_ npm
609       911430  0.0  0.0 667972 22116 ?        Sl   Mar27   0:06              \_ /opt/alt/alt-nodejs10/root/usr/bin/node server.js node server

This is the output in the terminal. There i took 435501 .

I have some problem with this comand nohup strace -ttp 435501 -o /tmp/strace.log. When i start this command in console i have error message nohup: ignoring input and appending output to 'nohup.out'. Please help me

alikenski avatar Apr 10 '19 12:04 alikenski

nohup: ignoring input and appending output to 'nohup.out'. is not error message, but just a tips which you can ignore. And the command should be nohup strace -ttp 435500 -o /tmp/strace.log & , do not forget &. Pid is master process pid which is 435500 not 435501 in your case.

walkor avatar Apr 15 '19 10:04 walkor

@walkor

[SERVER@SER tmp]$ tail -n 1000 strace.log
0x7ffc8f586c9c, WSTOPPED, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
05:42:25.947418 --- SIGHUP {si_signo=SIGHUP, si_code=SI_USER, si_pid=1185526, si_uid=0} ---
05:42:25.949504 +++ killed by SIGHUP +++

alikenski avatar Apr 17 '19 03:04 alikenski

@walkor is that things that you wanted to look?

alikenski avatar Apr 18 '19 10:04 alikenski

Upload all your codes.

walkor avatar Apr 18 '19 10:04 walkor

@walkor Good day Sir. My project should go on production and i have the same problem. When nobody uses website phpsocket.io stops. Please contact me

alikenski avatar May 09 '19 05:05 alikenski

@walkor This is last notes from strace.log

11:21:15.969949 munmap(0x7f76dcbe3000, 2453344) = 0
11:21:15.973534 munmap(0x7f76dd115000, 2150080) = 0
11:21:15.973673 munmap(0x7f76dce3a000, 2990592) = 0
11:21:15.973882 munmap(0x7f76dd322000, 2143400) = 0
11:21:15.974047 munmap(0x7f76dd52e000, 2107072) = 0
11:21:15.974372 munmap(0x7f76ddbf3000, 2117280) = 0
11:21:15.974477 munmap(0x7f76dd731000, 2099376) = 0
11:21:15.974574 munmap(0x7f76dd932000, 2885912) = 0
11:21:15.974793 munmap(0x7f76dddf8000, 2122424) = 0
11:21:15.974989 munmap(0x7f76ddfff000, 2362568) = 0
11:21:15.975284 munmap(0x7f76de240000, 2231856) = 0
11:21:15.975734 munmap(0x7f76de6f0000, 2121192) = 0
11:21:15.975842 munmap(0x7f76de461000, 2679408) = 0
11:21:15.976111 munmap(0x7f76ded78000, 2136520) = 0
11:21:15.976226 munmap(0x7f76deb50000, 2258168) = 0
11:21:15.976333 munmap(0x7f76de8f6000, 2465000) = 0
11:21:15.976504 munmap(0x7f76def82000, 2119344) = 0
11:21:15.976711 munmap(0x7f76df188000, 2123536) = 0
11:21:15.976941 munmap(0x7f76df38f000, 2197824) = 0
11:21:15.977171 munmap(0x7f76df80f000, 2162368) = 0
11:21:15.977323 munmap(0x7f76df5a8000, 2516128) = 0
11:21:15.977612 munmap(0x7f76dfa1f000, 2230480) = 0
11:21:15.977850 munmap(0x7f76dfc40000, 2144776) = 0
11:21:15.978053 munmap(0x7f76dfe4c000, 2378656) = 0
11:21:15.978287 munmap(0x7f76e04cc000, 2140736) = 0
11:21:15.978392 munmap(0x7f76e029a000, 2301280) = 0
11:21:15.978489 munmap(0x7f76e0091000, 2132136) = 0
11:21:15.978680 munmap(0x7f76e7319000, 2157040) = 0
11:21:15.979094 munmap(0x7f76e20e9000, 2158240) = 0
11:21:15.979208 munmap(0x7f76e1c7e000, 2426160) = 0
11:21:15.979363 munmap(0x7f76e1ecf000, 2201520) = 0
11:21:15.979462 munmap(0x7f76e1a6f000, 2155816) = 0
11:21:15.979560 munmap(0x7f76e181c000, 2434568) = 0
11:21:15.979683 munmap(0x7f76e15ef000, 2280672) = 0
11:21:15.979787 munmap(0x7f76e12a7000, 3438440) = 0
11:21:15.979899 munmap(0x7f76e1078000, 2288592) = 0
11:21:15.980004 munmap(0x7f76e0e74000, 2109704) = 0
11:21:15.980102 munmap(0x7f76e0c6f000, 2113912) = 0
11:21:15.980205 munmap(0x7f76e0a30000, 2354368) = 0
11:21:15.980364 munmap(0x7f76e22f8000, 2139760) = 0
11:21:15.980745 munmap(0x7f76e3f42000, 2472832) = 0
11:21:15.980859 munmap(0x7f76e2503000, 2144528) = 0
11:21:15.980962 munmap(0x7f76e3bac000, 3758208) = 0
11:21:15.981067 munmap(0x7f76e385a000, 3479584) = 0
11:21:15.981177 munmap(0x7f76e270f000, 18130504) = 0
11:21:15.981462 munmap(0x7f76e48e2000, 2194856) = 0
11:21:15.981573 munmap(0x7f76e45d0000, 3218408) = 0
11:21:15.981703 munmap(0x7f76e43c2000, 2150944) = 0
11:21:15.981808 munmap(0x7f76e419e000, 2241080) = 0
11:21:15.981966 munmap(0x7f76e4afa000, 2141528) = 0
11:21:15.982155 munmap(0x7f76e4f60000, 2148240) = 0
11:21:15.982283 munmap(0x7f76e4d05000, 2469632) = 0
11:21:15.982427 munmap(0x7f76e516d000, 2107608) = 0
11:21:15.982844 munmap(0x7f76e69e2000, 2516704) = 0
11:21:15.982962 munmap(0x7f76e6784000, 2480520) = 0
11:21:15.983068 munmap(0x7f76e6236000, 2165496) = 0
11:21:15.983167 munmap(0x7f76e6447000, 3394952) = 0
11:21:15.983321 munmap(0x7f76e6010000, 2250552) = 0
11:21:15.983419 munmap(0x7f76e5dc0000, 2423648) = 0
11:21:15.983517 munmap(0x7f76e5a35000, 3711984) = 0
11:21:15.983641 munmap(0x7f76e5798000, 2739312) = 0
11:21:15.983743 munmap(0x7f76e5573000, 2246440) = 0
11:21:15.983840 munmap(0x7f76e5370000, 2106112) = 0
11:21:15.983984 munmap(0x7f76e6c49000, 2146272) = 0
11:21:15.984129 munmap(0x7f76e6e55000, 4994208) = 0
11:21:15.984346 munmap(0x7f76e06d7000, 3508832) = 0
11:21:15.984545 munmap(0x7f76e7c4d000, 2117344) = 0
11:21:15.984674 munmap(0x7f76e7a42000, 2139552) = 0
11:21:15.984774 munmap(0x7f76e783f000, 2107224) = 0
11:21:15.984870 munmap(0x7f76e7528000, 3237912) = 0
11:21:15.985209 munmap(0x7f76e7e52000, 2273064) = 0
11:21:15.985471 munmap(0x7f76e8670000, 2148080) = 0
11:21:15.985602 munmap(0x7f76e82fb000, 3621696) = 0
11:21:15.985716 munmap(0x7f76e807d000, 2610712) = 0
11:21:15.986548 munmap(0x7f76e99e4000, 2181104) = 0
11:21:15.986680 munmap(0x7f76e975c000, 2650920) = 0
11:21:15.986788 munmap(0x7f76e9537000, 2246552) = 0
11:21:15.986924 munmap(0x7f76e930f000, 2257376) = 0
11:21:15.987026 munmap(0x7f76e90ed000, 2235440) = 0
11:21:15.987122 munmap(0x7f76e8e81000, 2538792) = 0
11:21:15.987270 munmap(0x7f76e8a9c000, 4083672) = 0
11:21:15.987394 munmap(0x7f76e887d000, 2222432) = 0
11:21:15.987528 munmap(0x7f76e9bf9000, 2107896) = 0
11:21:15.987697 munmap(0x7f76e9dfc000, 2126464) = 0
11:21:15.987859 munmap(0x7f76ea215000, 2120408) = 0
11:21:15.987959 munmap(0x7f76ea004000, 2162768) = 0
11:21:15.988098 munmap(0x7f76ea41b000, 2124512) = 0
11:21:15.990853 shmdt(0x7f76da4e3000)   = 0
11:21:15.990974 shmctl(215842818, IPC_RMID, 0x7ffeea291bc0) = -1 EINVAL (Invalid argument)
11:21:15.991073 close(3)                = 0
11:21:15.991187 munmap(0x7f76da4e2000, 4096) = 0
11:21:15.991320 unlink("/tmp/ZCUDb7uxwb") = -1 ENOENT (No such file or directory)
11:21:15.991441 munmap(0x7f76eabbb000, 2195064) = 0
11:21:15.991569 munmap(0x7f76ea852000, 3573032) = 0
11:21:15.991733 munmap(0x7f76ea622000, 2292232) = 0
11:21:15.993493 munmap(0x7f76eec96000, 1052672) = 0
11:21:15.993740 munmap(0x7f76eed97000, 266240) = 0
11:21:15.993863 munmap(0x7f76eec47000, 323584) = 0
11:21:15.994446 exit_group(0)           = ?
11:21:15.995650 +++ exited with 0 +++

alikenski avatar May 10 '19 05:05 alikenski

cd your project and show the outputs for command grep daemonize ./ -Rn.

walkor avatar May 10 '19 08:05 walkor

@walkor

./socket/vendor/workerman/workerman/Worker.php:252:    public static $daemonize = false;
./socket/vendor/workerman/workerman/Worker.php:502:        static::daemonize();
./socket/vendor/workerman/workerman/Worker.php:724:        if (static::$daemonize) {
./socket/vendor/workerman/workerman/Worker.php:810:            if ($command2 === '-d' || static::$daemonize) {
./socket/vendor/workerman/workerman/Worker.php:836:                    static::$daemonize = true;
./socket/vendor/workerman/workerman/Worker.php:908:                        static::$daemonize = true;
./socket/vendor/workerman/workerman/Worker.php:1117:    protected static function daemonize()
./socket/vendor/workerman/workerman/Worker.php:1119:        if (!static::$daemonize || static::$_OS !== OS_TYPE_LINUX) {
./socket/vendor/workerman/workerman/Worker.php:1148:        if (!static::$daemonize || static::$_OS !== OS_TYPE_LINUX) {
./socket/vendor/workerman/workerman/Worker.php:2041:        if (!static::$daemonize) {
./socket/vendor/workerman/workerman/Connection/TcpConnection.php:757:            if (!Worker::$daemonize) {

alikenski avatar May 23 '19 06:05 alikenski

@walkor Good day mister Walkor. The script stops when nobody use the website. Maybe PHPSocket.io will work when at least one web browser is connected?

alikenski avatar May 23 '19 06:05 alikenski

Daemon mode does not require browser connections. Nobody has post similar issue at the moment. I think it's probably because your PHP uses some extension not stable that causes this problem.

Can you try another machine and php version?

walkor avatar May 23 '19 09:05 walkor

@walkor Sorry but no. It is our company's server. Now i have one idea it is run command php server.php start -d via Cron. I have tried it but the error message was only run in command line mode . Do you have any idea to solve this?

alikenski avatar May 23 '19 09:05 alikenski

Try command nohup php server.php start & . with out -d but &. This command can also run server.php as daemon mode. No need to use cron.

walkor avatar May 24 '19 01:05 walkor

I solved the problem taking out the permanent PDO connection inside the server.

Before, I was starting a PDO connection together with the socket server, without close. I changed it to open and close the PDO connections only where I really need to use it.

The real problem: MySql server close instantly all long connections, and this exception cause failures on socket server

alissonpelizaro avatar Dec 11 '19 13:12 alissonpelizaro