Question

A script has an execution time of more than a minute. So, therefore I would like to run the script as a background task.

I've read a lot about it on the internet and read that print shell_exec('/usr/bin/php -q page.php &'); isn't the solution since the taks is still a child of the process. I've tested it with sleep(10) and indeed, the page which should call the cron job is waiting for 10 seconds.

So, symcbean have written an article ( http://symcbean.blogspot.nl/2010/02/php-and-long-running-processes.html?m=1 ) and is suggesting the following code:

print `echo /usr/bin/php -q longThing.php | at now`;

But, unfortunately, i script didn't do anything and after adding 2>&1 I get the following response:

sh: at: command not found

I've search a lot for solving this issue, but can't find any solution.

Was it helpful?

Solution

You should provide the fully qualified path to the at command for example /bin/at.

If you're not sure of the path you can usually type which at at the command line to find the path to the command.

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