tags:

views:

241

answers:

2

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.

+1  A: 

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
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?
Gian Basagre
I 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
A: 

Consider implementing it as a daemon: http://pear.php.net/package/System_Daemon

rscherer