0

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Good info. Seems like a good solution when php is (mis)used as a daemon.
0

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

3 Comments

Hi Kasim, Thanks for your answer. For the first question - ok. For the second question - can you help me with this? I can't find the answer.
Hi Kasim, I understand how to run crons. But what the running cron should do? I don't need to run the php script as cron, I need to run a script that checked if the php script is running, if not, it execute it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.