Question

I created a cronjob which call a php-script every 5mins.

This PHP script needs to start several other PHP CLI scripts and keep them running in background even when the cron-script terminates.

I'm currently creating these sub-processes by the following line of code:

if (!$pid = shell_exec("nohup /var/[..]/cake.php test doSomething > /dev/null 2>&1 & echo $!")) return false;  

When I call the "motherscript" via command-line everything's working great. But it seems like the sub-processes startet by the above line of code are terminated when the cron-job stops.

So how to spawn these cake.php test doSomethingscript and keep the child-process running under the predefined user in crontab?

Was it helpful?

Solution

That makes sense, you need to tell the children PHP scripts to NOT terminate when it's parent stops.

ignore_user_abort(true);

Add the above line to the children PHP scripts. Should do it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top