I finished a program with ZMQ, built a PHP Socket Program, and in order to accept some Client requests. I must be sure that this Server Program run in linux all the time.
I run this Program like this:php /app/server.php
.
And, the Terminal shows my output statement like waiting for client connecting...
, at this time, I can't use my Terminal to do others things, unless I Ctrl + c
to exit this program.
I want to let it automatical run in linux background like a progress. And the Program may die when PHP Error
, I have to restart this program manually.
I also want to it can restart self when error happened.
How to do that? Thank U first:)
Take a look at the System_Daemon PEAR package. I've used it several times and find that it works well.
Try using "Screen" program. you can use the following parameters to de-attach it from the current terminal and have your program running inside it.
screen -d -m php /app/server.php
also to have it autostart at boot time, add the above line to
/etc/rc.local
Use the & symbol at the end of the command to run the program in the background, like so: php /app/server.php &
You can put the above command in /etc/rc.local so that it starts automatically when the system boots.
If you program produces output, you might want send it to a log file instead of STDOUT.