1

Are there any readily available "Poor man's crontab" implementations (php script called every minute or so) that can be easily integrated into Zend Framework? Preferably utilizing a view script dashboard, for jobs management, populated by controller.

*Edit:

I found a Zend_Scheduler, which appear to do somewhat what I'm after. What's missing is a mechanism to stay self sustained (not rely on external crontabbed wget or similar), but execute on actual page loads.

Is there a suitable place in Zend framework I can piggyback $scheduler->run() from? Bootstrap::__destruct() or similar? In order to complete rendering the view, and push to client before any scheduled tasks take place? (So the client won't be affected by any long running taks that might be scheduled.

(Schedule naturally won't be accurate when there are no visitors, but my assumption here is that any scheduled task wouldn't have to be performed if no-one is around to see the result)

*Edit2:

Zend_Scheduler is so old, it's incompatible with newer Zend Framework versions, and thus not working as intended. Are there any other self sustained libraries that can be used for this?

j0k
  • 21,914
  • 28
  • 75
  • 84
Jon Skarpeteig
  • 4,053
  • 6
  • 32
  • 52
  • crontab is free. developing an alternate wouldn't be the poor man's solution ... developing == $$ ;) – sdolgy Jul 18 '11 at 11:37
  • I'm not looking for an alternative - I'm looking for a scheduler which utilize the 'poor mans's crontab' principle (E.G either being called every minute from an external source, or trigger on pageviews (After page rendering is complete) - with a single scheduler->run() dispatch – Jon Skarpeteig Jul 18 '11 at 12:07
  • Check this from Stackoverflow! [http://stackoverflow.com/questions/2819689/using-cron-mnager-from-within-php][1] [1]: http://stackoverflow.com/questions/2819689/using-cron-mnager-from-within-php – Adrian P. Mar 14 '14 at 14:21

3 Answers3

0

I guess you mean Drupal's poormanscron module. The Zend Framework does not ship with anything like that and actually neither does Drupal but they have modules which are created and supported by the Drupal community.

Zend Framework unfortunately is missing something like community driven modules. You have to find your modules somewhere in the wild. I doubt it you will find something like poormanscron but maybe you can take that module and with a few minor changes works in ZF.

Adrian World
  • 3,110
  • 2
  • 14
  • 25
0

You could write a Zend_Controller_Plugin that implements a dispatchLoopShutdown() method. I guess that'd be better than implementing $scheduler->run() in the Bootstrap-class. See http://framework.zend.com/manual/en/zend.controller.plugins.html for details.

Dennis R
  • 101
  • Wouldn't that halt the output of the view until the scheduled task has completed its run? – Jon Skarpeteig Jul 20 '11 at 11:35
  • Well that's true. I thought about putting the logic there that decides if a process needs to be executed. I'd put the execution itself in a background process, something like [ZendX_Console_Process_Unix](http://framework.zend.com/manual/en/zendx.console.process.unix.html) or an [register_shutdown_function()](http://de.php.net/register_shutdown_function) construct. If you're using PHP 5.3 with PHP-FPM FastCGI, you could also use [fastcgi_finish_request()](http://de.php.net/manual/en/install.fpm.php). – Dennis R Jul 21 '11 at 15:39
  • As for register_shutdown_function() that doesn't help here either: "4.1.0 The shutdown functions are now called as a part of the request." – Jon Skarpeteig Jul 23 '11 at 16:10
0

What I would do is a desktop app that would call some URL every x seconds (...say using wget). Piggibacking to regular request is bad idea IMO.

But in fact, you can put it after Boostrap->run(). The run method (when finished) returns the response to client, so you're free to mess with anything you need ;) I'd use some function to fetch an url (file_get_contents() or anything better - that doesn't need to wait for actual content - curl... maybe). And store the actual code on that URL. It's better than piggibacking the actual code to request...

Tomáš Fejfar
  • 10,505
  • 8
  • 48
  • 77