[development] estimating execution time left and hook_cron

Michael Prasuhn mike at mikeyp.net
Fri Sep 18 19:45:19 UTC 2009

You may want to check out the Job Queue module, as it provides the  
functionality you are looking for. You could either add a dependency  
on it (recommended) or at least read through the code to see how it  
works, to prevent timeouts (It has a feature to check execution time  
and stop processing if the time reached is half of the max execution  


Michael Prasuhn
503.512.0822 office
mike at mikeyp.net

On Sep 18, 2009, at 10:16 AM, nitin gupta wrote:

> Hello,
> I am maintaining the module feedapi imagegrabber, which pulls the  
> images from the original url of the feed items (just like google  
> reader). It is implemented on the top of feedapi and hence  
> implements the feedapi_after_refresh() hook, which is basically  
> fired by the feedapi after it has refreshed the feed.
> Now, as my module download images from an external website, I can  
> never be sure about the time it will take to complete the job of  
> downloading images for all the feed items. Therefore, sometimes I  
> get a 'fatal execution time exceeded error'. How can I know how much  
> execution time is left, so that I can return on time by saving the  
> rest of the work as a cron job?
> I have gone through the source code of FeedAPI which implements  
> hook_cron(). It uses a variable called 'cron_semaphore', which I am  
> guessing is some way to share execution time but am unable to get  
> how. I will really appreciate if someone can explain the above to me  
> or provide some tutorial links on writing a good hook_cron  
> implementation.
> --
> Regards,
> Nitin Kumar Gupta
> http://publicmind.in/blog/

More information about the development mailing list