Download the PHP package myclabs/work without Composer
On this page you can find all versions of the php package myclabs/work. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package work
Short Description Work queue library letting you run distributed tasks using a generic abstraction
License MIT
Informations about the package work
MyCLabs\Work is a work queue library letting you run tasks in background using a generic abstraction.
It's intent is to be compatible with classic work queue solutions (RabbitMQ, Beanstalkd, …) while offering a high level abstraction.
Current implementations:
- InMemory: synchronous implementation, task are executed directly (useful for tests or dev environments)
- RabbitMQ
- Beanstalkd
Feel free to contribute and submit other implementations (Gearman, …).
Extended guides:
- The InMemory adapter
- The RabbitMQ adapter
- The Beanstalkd adapter
- Listening to events
How it works
In you code (HTTP request for example), you can run a task in background:
Separately, you set up a worker to run continuously on the command line (like a deamon):
This worker simply calls:
Defining tasks
Define a task:
And define the code that executes the task:
Execute a task and wait for its result
The run($task)
method runs a task in background.
If you want to wait for the result of that task, you have to use a WorkDispatcher that implements the
\MyCLabs\Work\Dispatcher\SynchronousWorkDispatcher
interface.
For example, the RabbitMQ adapter implements this interface.
That interface offers the runAndWait
method:
Read more
Read more in the docs.
Contributing
You can run the tests with PHPUnit:
Some functional tests need external programs like RabbitMQ or Beanstalkd. For practical reasons, you can boot a VM very quickly using Vagrant and the included configuration. You can then run the tests in the VM: