Nir
Nir

Reputation: 1962

Linux Execute php file via command line

I have a php script of server working with sockets (in order to create a chat).

I want the script to run in the background (it have infinity loop), so I'm using this command:

php -q server.php &

In order to run the server.

It's works OK!

But I have two problems:

  1. I want to know if the script is stop running for some reason (via email notice)
  2. If it stop running, make it run again automatically (also if the server was restarted - the script should start run automatically

How can I achieve this two things?

Upvotes: 0

Views: 103

Answers (2)

MegaAppBear
MegaAppBear

Reputation: 1220

My suggestion is to use supervisord, once it's installed (download from http://supervisord.org/) and running, all you have to do is add a line to /etc/supervisord.conf - Something like this:

[program:foo]
command=/mypath/myprogram.php
autorestart=true
stdout_logfile=/mylogs/myprogram.log
stderr_logfile=/mylogs/myprogram.err

Upvotes: 1

sfdeveloper
sfdeveloper

Reputation: 196

This is how you can try for your questions,

Q. I want to know if the script is stop running for some reason (via email notice)

Ans. Do some error handling in script. if any point of time error occurs, your mail script should be executed.

Q. If it stop running, make it run again automatically (also if the server was restarted - the script should start run automatically

Ans. Set the cron on your server with proper script path.(google for this)

thanks

Upvotes: 0

Related Questions