How to run web socket scripts coded in PHP in the Plesk web hosting control panel. I need to run the PHP WebSocket scripted in PHP 24/7/365. The path of the script named websocket_server.php lies in the path: /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/websocket_server.php
In order to run the above script first, it needs to register as a service and invoke this command automatically. I didn't have much knowledge about setting up the service in Linux (Ubuntu 16.04). So I had gone with setting up the cron job scheduler. But it didn't yield any results because of errors.
I had added three commands in order to run in task scheduler they are as follows:
@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 foundhttpdocs/proj_ci/application/libraries/server/websocket_launch.sh > with arguments cron:runTask
httpdocs/proj_ci/application/libraries/server/websocket_launch.shsuccessfully 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.phpTask
/usr/bin/php /var/www/vhosts/abc.xy/httpdocs/proj_ci/application/libraries/server/websocket_server.phpcompleted 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
This is from the PuTTY terminal:
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#
Apart from adding cron jobs are there any better ways to do so? Please help me with the solution as much as possible. Since from the PuTTY terminal, I was able to run the command and everything works fine.