Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smuuf/celery-for-php
A modern PHP client library for Celery.
https://github.com/smuuf/celery-for-php
celery client distributed php python queue tasks
Last synced: 2 months ago
JSON representation
A modern PHP client library for Celery.
- Host: GitHub
- URL: https://github.com/smuuf/celery-for-php
- Owner: smuuf
- License: mit
- Created: 2023-09-01T22:12:50.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-11-14T15:01:52.000Z (about 1 year ago)
- Last Synced: 2024-03-14T19:54:15.172Z (10 months ago)
- Topics: celery, client, distributed, php, python, queue, tasks
- Language: PHP
- Homepage:
- Size: 66.4 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# celery-for-php 🌱
[![PHP tests](https://github.com/smuuf/celery-for-php/actions/workflows/php.yml/badge.svg)](https://github.com/smuuf/celery-for-php/actions/workflows/php.yml)
A modern PHP client library for [Celery - Distributed Task Queue](https://docs.celeryq.dev).
## Requirements
- PHP 8.0+## Installation
Install [celery-for-php](https://packagist.org/packages/smuuf/celery-for-php) via Composer.
```bash
composer require smuuf/celery-for-php
```### Redis (Predis)
If you want to use Redis as a broker and/or result backend, celery-for-php contains a Redis driver backed by [`Predis`](https://github.com/predis/predis).
The Predis `Client` object then needs to be wrapped in our `Smuuf\CeleryForPhp\Drivers\PredisRedisDriver` driver object, which provides the necessary interface for celery-for-php's actual communication with Redis.
#### Example usage
```php
'127.0.0.1']);
$redisDriver = new PredisRedisDriver($predis);$celery = new Celery(
new RedisBroker($redisDriver),
new RedisBackend($redisDriver),
// Optionally explicit config object.
// config: new \Smuuf\CeleryForPhp\Config(...)
);$task = new TaskSignature(
taskName: 'my_celery_app.add_numbers',
queue: 'my_queue', // Optional, 'celery' by default.
args: [1, 3, 5],
// kwargs: ['arg_a' => 123, 'arg_b' => 'something'],
// eta: 'now +10 minutes',
// ... or more optional arguments.
);// Send the task into Celery.
$asyncResult = $celery->sendTask($task);// Wait for the result (up to 10 seconds by default) and return it.
// Alternatively a \Smuuf\CeleryForPhp\Exc\CeleryTimeoutException exception will
// be thrown if the task won't finish in time.
$result = $asyncResult->get();
// $result === 9
```### AMQP/RabbitMQ (PhpAmqpLib)
You can use AMQP/RabbitMQ as the broker instead, with Redis as the backend. celery-for-php contains a AMQP driver backed by [`PhpAmqpLib`](https://github.com/php-amqplib/php-amqplib).
The PhpAmqpLib `AMQPConnection` or `AMQPSSLConnection` object needs to be wrapped in our `Smuuf\CeleryForPhp\Drivers\PhpAmqpLibAmqpDriver` driver object, which provides the necessary interface for celery-for-php's actual communication via AMQP.
#### Example usage
```php
false]]);
$amqpDriver = new PhpAmqpLibAmqpDriver($amqpConn);$predis = new PredisClient(['host' => '127.0.0.1']);
$redisDriver = new PredisRedisDriver($predis);$celery = new Celery(
new AmqpBroker($amqpDriver),
new RedisBackend($redisDriver),
// Optionally explicit config object.
// config: new \Smuuf\CeleryForPhp\Config(...)
);$task = new TaskSignature(
taskName: 'my_celery_app.add_numbers',
queue: 'my_queue', // Optional, 'celery' by default.
args: [1, 3, 5],
// kwargs: ['arg_a' => 123, 'arg_b' => 'something'],
// eta: 'now +10 minutes',
// ... or more optional arguments.
);// Send the task into Celery.
$asyncResult = $celery->sendTask($task);// Wait for the result (up to 10 seconds by default) and return it.
// Alternatively a \Smuuf\CeleryForPhp\Exc\CeleryTimeoutException exception will
// be thrown if the task won't finish in time.
$result = $asyncResult->get();
// $result === 9
```