1

Originally I had a cronjob that executed a php file every day. Apparently the php file was to heavy and the cronjob was not executing it.

I opted for creating a Daemon that sleeps for 24hrs and works perfectly well, except that I believe that the server kills this process after a certain time due to its inactivity. I have a DEAMON that runs every 5 minutes and this one never stops, but the one that waits for 24 hrs always stops working.

My plan is to create a cronjob that checks if the process is running, if not to execute it:

exec("ps auxwww|grep _DAEMON.php|grep -v grep", $output);
if(empty($output)){
   exec("php -f _DAEMON.php");
}

For some reason this is not working, exec("ps auxwww|grep _DAEMON.php|grep -v grep", $output) does detect perfectly well if the script is running or not, so exec("php -f _DAEMON.php") is the one that doesn't work.

I tried to print_r $status from exec("php -f _DAEMON.php",$status); and this is what I got:

Array
(
    [0] => X-Powered-By: PHP/5.2.17
    [1] => Content-type: text/html
    [2] => 
)

I tried exec("php-cli -f _DAEMON.php") and worked perfectly well, but since the file I am calling is a daemon, php-cli makes it part of my original file (some kind of include() I believe) and freezes my original file, it does create a separate new process for the daemon, but the original file loads forever.

Any ideas? thanks!

9
  • _DAEMON.php is different from _RANDOMSD.php. So what is the result of executing exec("php -f _DAEMON.php"); ? Commented Jul 6, 2013 at 4:07
  • so sorry typo. I just fixed it Commented Jul 6, 2013 at 4:10
  • 1
    See this: stackoverflow.com/questions/566248/… Commented Jul 6, 2013 at 4:12
  • Thanks @ShivanRaptor this worked, now the problem is that whatever is executed in php-cli becomes part of the original script, and since my second script is a daemon it freezes. :( Commented Jul 6, 2013 at 4:26
  • @ShivanRaptor please look at the bottom of my question, I added your solution and the problem I got into, thanks! Commented Jul 6, 2013 at 4:32

0

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.