Timed Tasks (cron-like) in PHP

2019-01-14 17:23发布

问题:

Is there a full featured, job scheduling package available for PHP? I'm looking for the PHP equivalent to Java's Quartz. I'm fine having things triggered externally from cron to drive the system. The functionality I'd be looking for:

  • Ability to register task (class/method) to be called at given intervals.
  • Ability to specify whether a given task can be run multiple times (potentially long running methods should not be run multiple times in certain cases).
  • All registered entries/methods could be run in parallel (jobs are backgrounded so that they do not block other timed tasks).
  • Ability to set a timeout for a given task.
  • Ability to update job control dynamically, so for instance you could disable some tasks or change their frequency without code changes.

I know it is a lot to ask, but it seems like a useful batch of features and I thought someone might have put together some portion of them.

If this or some portion of this does not already exist, any pointers to putting one together or an open source project that has a reasonably featureful implementation of some subset of these?

回答1:

A quick google turns up a few decent results:

  • http://www.bitfolge.de/pseudocron-en.htm
  • http://www.phpclasses.org/browse/package/4140.html
  • http://www.hotscripts.com/Detailed/61437.html

Really, though, if you're on any decent shared hosting package you should have access to some sort of task scheduler be it Windows' Task Scheduler or cron under *nix. I know DreamHost allows user level crontabs, at least.

HTH



回答2:

We ported Java's quartz library to PHP (https://github.com/php-quartz). The code look is as close to Java as it possible.

It has some additional features like:

  • An integration with message queues so jobs could be executed in any language.
  • There is an ability to use it as standalone service.