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!