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
*/1 * * * * pgrep reportsGeneratorByCron > /dev/null || php /home/john/public_html/reportsGeneratorByCron.php
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: