-1

I need to generate some charts and reports, but only when my DB is modified. Because the time needed to generate the reports varies between 2 and 4 seconds and the number of reports varies too I'm thinking to use a cron which checks for DB modifications. The thing is that I don't wish to start generating another report, while other is running. In other words I don't wish to start another process while the previous one is still running. How can I accomplish this?

my cron look like this:

*/1 * * * * php /home/john/public_html/reportsGeneratorByCron.php
dole doug
  • 34,070
  • 20
  • 68
  • 87
  • 2
    You can put some flag on database or in some file on disc which you will have to check with other processes to find out if it's unlocked. – Kelu Thatsall Nov 16 '13 at 18:41
  • I would investigate using database triggers to add a report request to a queue and then have a process which reads report requests from the queue and process them. This does not sound like something for a cron job. – Richard Chambers Nov 16 '13 at 18:41
  • take a look at this kind of approach http://stackoverflow.com/questions/11357187/php-how-do-i-implement-queue-processing-in-php – Richard Chambers Nov 16 '13 at 18:47

2 Answers2

1

Take a look at the Fat Controller which works like CRON but allows you to specify the time between one process ending and another one starting, rather than the time between starts like CRON.

Take a look at the website - there's plenty of documentation, examples and use cases:

http://fat-controller.sourceforge.net/

SlappyTheFish
  • 2,344
  • 3
  • 34
  • 41
0
*/1 * * * * pgrep reportsGeneratorByCron > /dev/null || php /home/john/public_html/reportsGeneratorByCron.php
Dmitry Seleznev
  • 955
  • 7
  • 7