Is it possible for CakePHP to execute a cakephp shell task on background for i.e running long reports. I would also want to update the current status back to the user via updating a table during the report generation and querying using Ajax.
Asked
Active
Viewed 3,990 times
2 Answers
3
Yes, you can run shells in the background via normal system calls like
/path/to/cake/console/cake -app /path/to/app/ <shell> <task>
The tricky part is to start one asynchronously from PHP; the best option would be to put jobs in a queue and run the shell as a cron job every so often, which then processes the queue. You can then also update the status of the job in the queue and poll that information via AJAX.

deceze
- 510,633
- 85
- 743
- 889
-
Do you have any other option? Because as far as I know, cron jobs can be scheduled only every minute. So what if the process was queued right after the last cron job was run, it has to wait for a minute right? – codegy Jul 13 '09 at 10:03
-
1I was under the impression your jobs took longer, so a minute or two wouldn't matter. See here: http://stackoverflow.com/questions/984577/php-need-a-cron-for-back-site-processing-on-user-signup-or-fork-process – deceze Jul 13 '09 at 11:00
-
@deceze how to give this path - /path/to/cake/console/cake -app /path/to/app/
in crontab? -
1@Abhi Well, exactly like that. `/myapp/cake/console/cake -app /myapp/app foo bar` – deceze Nov 05 '11 at 07:28
-
Somehow I can run cakephp console tasks as workers when deploying to Pagoda Box. All I have to do is put "app/cake/Console foo bar" in the Boxfile under worker1's exec. But on a normal server, I don't quite understand why I have to do all these workarounds w/ cron jobs etc. In fact when I run a Console script without "&" at the end, it works fine, but when I add "&" so it runs in the background, it doesn't work (even though it's still in the "top" task list). Why is that? – Brade Jul 17 '13 at 14:05
-
I am facing similar problem in cakephp 2, Do you have resolved it? – dpkrai96 Dec 24 '19 at 10:08
2
Consider implementing it as a daemon: http://pear.php.net/package/System_Daemon

nanoman
- 1,069
- 12
- 27