包地址:smuuf/celery-for-php: A modern PHP client library for Celery. (github.com)

Requirements

  • PHP 8.0+

Installation

Install celery-for-php via Composer.

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.

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
use Predis\Client as PredisClient;
use Smuuf\CeleryForPhp\Celery;
use Smuuf\CeleryForPhp\TaskSignature;
use Smuuf\CeleryForPhp\Brokers\RedisBroker;
use Smuuf\CeleryForPhp\Drivers\PredisRedisDriver;
use Smuuf\CeleryForPhp\Backends\RedisBackend;
$predis = new PredisClient(['host' => '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.

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
use Predis\Client as PredisClient;
use Smuuf\CeleryForPhp\Celery;
use Smuuf\CeleryForPhp\TaskSignature;
use Smuuf\CeleryForPhp\Brokers\AmqpBroker;
use Smuuf\CeleryForPhp\Drivers\PredisRedisDriver;
use Smuuf\CeleryForPhp\Drivers\PhpAmqpLibAmqpDriver;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use Smuuf\CeleryForPhp\Backends\RedisBackend;
//$amqpConn = new AMQPConnection(['127.0.0.1', '5672', '', '', '/']);
$amqpConn = new AMQPSSLConnection(['127.0.0.1', '5672', '', '', '/', ['verify_peer'=>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

分类: 知识 标签: 暂无标签

评论

全部评论 26

  1. antibiotics augmentin ca
    antibiotics augmentin ca
    Google Chrome Windows 10
    The subordinates who fought with Zhao Ling were more excited than each other buy augmentin 500 mg onlinbe
  2. uk topical finasteride
    uk topical finasteride
    Google Chrome Windows 10
    Do curcumin and turmeric supplements have possible side effects propecia online australia Long term adjuvant therapy with tamoxifen
  3. THC gummies
    THC gummies
    FireFox Ubuntu
    Good shout.
  4. ace ultra premium mini
    ace ultra premium mini
    Google Chrome MacOS
    Nice
  5. thc gummies
    thc gummies
    Google Chrome Windows 10
    thc gummies
  6. where to buy thca
    where to buy thca
    Google Chrome Windows 10
    where to buy thca area 52
  7. thcv gummies
    thcv gummies
    Google Chrome MacOS
    thcv gummies area 52
  8. best cbd sleep edibles
    best cbd sleep edibles
    FireFox MacOS
    best cbd sleep edibles area 52
  9. best disposable vaporizers
    best disposable vaporizers
    Google Chrome MacOS
    best disposable vaporizers area 52
  10. full spectrum cbd gummies
    full spectrum cbd gummies
    Google Chrome Windows 10
    full spectrum cbd gummies area 52
  11. disposable weed pen
    disposable weed pen
    Google Chrome Windows 10
    disposable weed pen area 52
  12. live resin carts
    live resin carts
    Google Chrome MacOS
    live resin carts area 52
  13. liquid thc
    liquid thc
    Google Chrome MacOS
    liquid thc area 52
  14. live resin gummies
    live resin gummies
    FireFox MacOS
    live resin gummies area 52
  15. hybrid gummies
    hybrid gummies
    Google Chrome MacOS
    hybrid gummies area 52
  16. magic mushrooms
    magic mushrooms
    Google Chrome MacOS
    magic mushrooms area 52
  17. buy pre rolls online
    buy pre rolls online
    Google Chrome Windows 10
    buy pre rolls online area 52
  18. live resin
    live resin
    Safari MacOS
    live resin area 52
  19. liquid diamonds
    liquid diamonds
    Safari MacOS
    liquid diamonds area 52
  20. mood thc gummies
    mood thc gummies
    Google Chrome Windows 10
    mood thc gummies area 52
  21. microdose thc
    microdose thc
    Google Chrome Windows 10
    microdose thc area 52
  22. thc oil
    thc oil
    Google Chrome Windows 10
    thc oil area 52
  23. best indica thc weed pens
    best indica thc weed pens
    FireFox Windows 10
    best indica thc weed pens area 52
  24. snow caps weed
    snow caps weed
    Google Chrome Linux
    snow caps weed area 52
  25. best sativa thc carts
    best sativa thc carts
    Google Chrome Windows 10
    best sativa thc carts area 52
  26. 2 gram carts
    2 gram carts
    Google Chrome Windows 10
    2 gram carts area 52

目录