我需要运行以 PHP 24/7/365 编写的 PHP WebSocket
名为 websocket_server.php 的脚本的路径位于以下路径中
/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/websocket_server.php
为了首先运行上述脚本,它需要注册为服务并自动调用此命令。我对在 Linux(Ubuntu 16.04)中设置服务知之甚少。所以我开始设置皇冠作业调度程序。但由于错误,它没有产生任何结果。
为了在任务调度程序中运行,我添加了三个命令,它们如下:
@reboot root nohup php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php 2>&1 >/dev/null &
Task "@reboot root nohup php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/websocket_server.php 2>&1 >/dev/null &" successfully completed in 0 seconds, output: -: @reboot: command not found
httpdocs/proj_ci/application/libraries/server/websocket_launch.sh 带参数 cron:run
Task "httpdocs/proj_ci/application/libraries/server/websocket_launch.sh" successfully completed in 0 seconds, output: PID=
ps -aef | grep "websocket_server.php" | grep -v grep | awk '{print $2}'
if [ -z $PID ] then #echo "Launching now" nohup php websocket_server.php > error_log & else # echo "Running as PID $PID" fi
/usr/bin/php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php
Task "/usr/bin/php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php" completed with error in 0 seconds, output:
Could not open input file: /usr/bin/php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php
这是来自 PuTTY 终端
root@h3069528:/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries# php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php
PHP Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php on line 10
PHP Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.php on line 10
root@h3069528:/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries# cd /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server
root@h3069528:/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server# php websocket_server.php ^C
root@h3069528:/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server#
root@h3069528:/var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server#
除了增加皇冠职位,还有什么更好的方法吗?请尽可能帮助我解决问题。由于从 PuTTY 终端,我可以运行命令并且一切正常