Bernard is a multi-backend PHP library for creating background jobs for later processing.

Related tags

Queue bernard
Overview

Bernard

Latest Version Minimum PHP Version GitHub Workflow Status Total Downloads

Bernard makes it super easy and enjoyable to do background processing in PHP. It does this by utilizing queues and long running processes. It supports normal queueing drivers but also implements simple ones with Redis and Doctrine.

Currently these are the supported backends, with more coming with each release:

  • Predis / PhpRedis
  • Amazon SQS
  • Iron MQ
  • Doctrine DBAL
  • Pheanstalk
  • PhpAmqp / RabbitMQ
  • Queue interop

Install

Via Composer

$ composer require bernard/bernard

Documentation

Please see the official documentation.

Testing

We try to follow BDD and TDD, as such we use both phpspec and phpunit to test this library.

$ composer test

You can run the functional tests by executing:

$ composer test-functional

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Add queue interop driver

    Add queue interop driver

    The driver can work with any queue interop compatible transport such as:

    It also provide an extended driver version for amqp interop compatible transports. It supports some amqp specific features such as queue declaration and message couting.

    TODO:

    • [x] add tests
    • [x] add doc

    I welcome everyone who is interested in MQs to join the queue interop group

    opened by makasim 36
  • Added options array to queue create and message produce

    Added options array to queue create and message produce

    Added options array to queue create and message send/push so we can pass options to the specific methods of each driver.

    I've added this to fix #205, but I will expand it usage of the options so you can use all options of each driver method (queue create params and message push params)

    I will create a seperate PR to add the docs for this and one for the usage of all params (for each specifc driver)

    TODO:

    • [x] Check if all option definitions are ok
    • [x] Fix travis-ci build config so we test against symfony 2.3 and 3.0 (options-resolver)
    • [x] Add BC layer to each configure*Options method (to support 2.3 and 3.0)
    opened by acrobat 22
  • Default message name

    Default message name

    Two years old, still one of my most linked article: http://verraes.net/2013/09/sensible-interfaces/

    One of the points here (which I agree with) is that Default means nothing. Default what?

    Although it is a default implementation, I think PlainMessage sounds better. WDYT?

    opened by sagikazarmark 17
  • bernard with supervisord

    bernard with supervisord

    i am having a weird issue with bernard, when i run the command to consume manually on the console it works fine, however when i tell supervisord to run things, supervisord still works ok, but the php process is stopped and does not continue/finish == no logs to debug.

    here is my conf:

    [program:algorithmOne]
    command=/usr/bin/php index.php consume algorithm-one
    process_name=%(program_name)s
    numprocs=1
    directory=/tmp
    priority=999
    autostart=true
    autorestart=true
    startretries=3
    stopwaitsecs=180
    user=root
    stdout_logfile=/var/log/supervisord.log
    stdout_logfile_maxbytes=25MB
    

    any hints on what could be happenign or how to go around it?

    opened by cordoval 16
  • Consumer pings

    Consumer pings

    Is it possible to somehow ping the consumers, or let the consumers notify when they are active? Would be very nice to assert that there are consumers running before dispatching work (if not fallback to "normal" approach).

    opened by davidsteinsland 14
  • Fix #251: dbal driver - safe queue creation

    Fix #251: dbal driver - safe queue creation

    Since we don't have UPSERT support in DBAL (and sadly will not be in it for a while), this PR fixes #251 by providing graceful handling of queue creation.

    1. operations are executed in a transaction
    2. only unique constraint exceptions are caught (very important! if the DB dies, that's not something we can ignore)
    3. avoid causing duplicate key issues, when possible
    opened by Ocramius 13
  • Messages are not marked as acknowledged

    Messages are not marked as acknowledged

    Somehow my messages are not marked as acknowledged in RabbitMQ and it seems not to work for other drivers as well. When I create a new default message like this;

    $this->get('bernard.producer')->produce(new DefaultMessage('SubmitMessage', [
        'id' => $entity->getId()
    ]));
    

    It goes correctly to a queue called submit-message. So I run a consumer like this;

    app/console bernard:consume submit-message --no-debug
    

    And it processes the message correctly. But it's never marked as acknowledged because of this line. The $queue variable contains the string SubmitMessage but the queue's key is submit-message, so this isset will always fail. Am I doing something wrong or is this a bug?

    opened by robinvdvleuten 13
  • DoctrineDriver - Use UUID instead of autoincrement ID's

    DoctrineDriver - Use UUID instead of autoincrement ID's

    We use the DoctrineDriver and every now and then we'll hit a dead lock.

    I think the reason for this is that the DoctrineDriver creates a bernard_messages table where the id is autoincrement.

    This locks the table every time an insert is executed.

    I think we should use UUID's and get rid of the autoincrement ids. The only problem is that we need to sort based on date + microtime.

    opened by ruudk 12
  • Current producer/consumer implementation is limited

    Current producer/consumer implementation is limited

    The current producer/consumer model is based on the assumption that messages are published with a specified envelope name that contributes to how they are routed; more specifically, that they are routed to a queue based on that envelope name and that a separate consumer process is maintained per queue.

    This is a very limiting architecture in infrastructures like Heroku, where I may only want to operate a single worker process across all queues because limited traffic doesn't warrant a separate process per queue.

    It is possible to work around this limitation by sending messages to a single queue, extending the router, and having it resolve the receiver differently based on some attribute other than the envelope name, such as a message argument.

    However, this solution is just that: a work-around. It would be nice if this was something the Bernard architecture supported natively through a more interface-driven design with consumers.

    opened by elazar 11
  • [RFC] Middlewares and Events

    [RFC] Middlewares and Events

    Have been thinking about Middlewares and how they work. I like them since they are easy to create and the interface is simple, i dont like them when you have functionality that are shared between consuming and producing. Because of that i propose the following.

    1. Use events where the middlewares are currently used consume, produce and exception.
    2. Create a Strategy implementation for executing messages. which will be a layer between the Consumer and calling the method.
    3. Remove the middleware notion.

    This work make the BatchMiddleware look as following (mockup).

    <?php
    
    namespace Bernard\EventDispatcher;
    
    use Bernard\Envelope;
    use Bernard\Queue;
    use Bernard\Batch\Storage;
    use Bernard\EventDispatcher;
    
    class BatchListener implements EventSubscriber
    {
        protected $storage;
    
        public function __construct(Storage $storage)
        {
            $this->storage;
        }
    
        public function onProduce(Envelope $envelope, Queue $queue)
        {
            if (false == $batch = $event->getEnvelope()->getStamp('batch')) {
                return;
            }
    
            $this->storage->register($batch);
        }
    
        public function onConsume(Envelope $envelope, Queue $queue)
        {
            if (false == $batch = $event->getEnvelope()->getStamp('batch')) {
                return;
            }
    
            $this->storage->increment($batch, 'consumed');
        }
    
        public function onException(Envelope $envelope, Queue $queue, $exception)
        {
            if (false == $batch = $event->getEnvelope()->getStamp('batch')) {
                return;
            }
    
            $this->storage->increment($batch, 'failed');
        }
    
        public function subscribe(EventDispatcher $dispatcher)
        {
            $dispatcher->on('bernard.consume', [$this, 'onConsume']);
            $dispatcher->on('bernard.exception', [$this, 'onException']);
            $dispatcher->on('bernard.produce', [$this, 'onProduce']);
        }
    }
    

    The convenience for this is that it will only requirering creating a single class for adding stuff of both the producer and consumer side.

    the Strategy is to provide a extension point for executing jobs in different ways suchs as threads or forks with Spork.

    opened by henrikbjorn 11
  • doctrine driver: Fix missing space in select ... for update

    doctrine driver: Fix missing space in select ... for update

    PR #216 has introduced a bug in the doctrine driver. It does not pop messages from a queue anymore and fails silently due to the try ... catch in DoctrineDriver::popMessage. After some debugging I've found the error in the select ... for update statement that was modified in the linked PR. Can you release a 0.12.4 with the fix please?

    opened by codeliner 9
  • Fix PHP 8.1 deprecation notices

    Fix PHP 8.1 deprecation notices

    This fixes the deprecation notices reported in #425 by specifying the int return type for the count functions.

    Initially I wanted to use the master branch but it is lacking the Predis driver that we use.

    I figured this would be more inclusive than using #[\ReturnTypeWillChange] given we only need to bump to PHP7 or higher and not PHP8.

    Since this removes support for PHP5 (about time I guess? :)) I would suggest to release this as 0.14.0.

    opened by AdrienPoupa 0
  • PHP 8.1 support

    PHP 8.1 support

    I use bernard with PHP 8.1, and it works, however there are some deprecation issues:

    PHP Deprecated:  Return type of Bernard\QueueFactory\PersistentFactory::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /webapps/vendor/bernard/bernard/src/Bernard/QueueFactory/PersistentFactory.php on line 68
    
    Deprecated: Return type of Bernard\QueueFactory\PersistentFactory::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /webapps/vendor/bernard/bernard/src/Bernard/QueueFactory/PersistentFactory.php on line 68
    
    PHP Deprecated:  Return type of Bernard\Queue\PersistentQueue::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /webapps/vendor/bernard/bernard/src/Bernard/Queue/PersistentQueue.php on line 49
    
    Deprecated: Return type of Bernard\Queue\PersistentQueue::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /webapps/vendor/bernard/bernard/src/Bernard/Queue/PersistentQueue.php on line 49
    
    opened by pszalko 2
  • Replace mixed with string|int|null in DriverMessage receipt?

    Replace mixed with string|int|null in DriverMessage receipt?

    Currently the receipt can be anything thanks to the mixed type hint. I wonder if that makes sense as mixed includes types, like resource, boolean and array.

    Are those types potential receipts?

    Object is something I could imagine as a receipt.

    opened by sagikazarmark 0
  • Serializer and general bernard questions

    Serializer and general bernard questions

    Hi,

    I am new to this project and I am trying to figure out how message serialization works. I know the default place for questions is usually stack overflow, but currently it doesn't have a bernard tag and I had a feeling that I would need to wait a few months to get an answer there :)

    Bernard installed from composer (currently v0.13) comes with Bernard\Serializer\SimpleSerializer class and suggests using symfony or JMS serializers instead. This doc says that currently bernard uses symfony serializer by default.

    On the other hand I couldn't find symfony/serializer in composer.json. The Bernard\Serializer namespace is gone and Bernard/Serializer class seems to use json_encode / json_decode. To confuse things even more, Bernard/Serializer is an interface in the latest composer and a class in the latest master branch.

    So I figured I should go read the docs again :) This doc says that if I plan to use a custom message class (which I do), then I must provide a normalizer for it. Except there is no such thing in the currently available composer version of bernard.

    My questions are:

    PHP native serialize() function should be able to handle simple classes like PlainMessage. Why does bernard need complex serializers from symfony or JMS even for the most basic message type?

    It seems that 0.x branch (which is installed by default via composer) is many years behind the current master and current documentation is no longer usable for 0.x. Is it generally a good idea to use the current master instead?

    opened by ninze 1
  • Update README to specify

    Update README to specify "bernard/bernard": "dev-master" in composer.json

    When I follow the README and executecomposer require bernard/bernard the version of bernard installed is, bernard/bernard": "^0.13.0". I see Bernard\Router\ReceiverMapRouter exists in master, and the only way I am aware of getting the latest version is if I spell out in my composer file the following "bernard/bernard": "dev-master".

    opened by robskrob 3
Releases(0.13.0)
  • 0.13.0(Jan 25, 2019)

  • 1.0.0-alpha9(Feb 14, 2018)

    ⚠️ Expect some major breaks after this release ⚠️

    This is the last alpha release, somewhat maintaining backwards compatibility. Major breaks are coming (mostly related to drivers). Please lock your dependencies or even better, do not depend on master at all.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-alpha8(Jan 13, 2018)

  • v1.0.0-alpha7(Nov 13, 2017)

  • v0.12.4(Nov 5, 2017)

  • v1.0.0-alpha6(Sep 15, 2017)

  • v1.0.0-alpha5(Jun 24, 2017)

  • 1.0.0-alpha4(Oct 12, 2016)

  • 1.0.0-alpha3(Mar 15, 2016)

  • 0.12.3(Jan 4, 2016)

  • 1.0.0-alpha2(Dec 5, 2015)

  • 1.0.0-alpha1(Nov 10, 2015)

  • 0.12.2(Feb 4, 2014)

  • 0.12.1(Jan 24, 2014)

  • 0.12.0(Jan 24, 2014)

    • Add FlatFileDriver
    • Move documentation into the repository so it is synchonized with the code.
    • Add __toString to Queue in order to have a easy way of getting its name.
    Source code(tar.gz)
    Source code(zip)
  • 0.11.0(Oct 7, 2013)

  • 0.10.1(Sep 23, 2013)

  • 0.10.0(Sep 23, 2013)

    The next release working towards the first stable. This release does unfortunately contain a lot of BC breaks.

    • Remove RetryMiddleware and add FailuresMiddleware that just sends failed messages to failed queue.
    • Add LoggerFactory for LoggerMiddleware.
    • Rename internal Bernard\Message\Envelope to Bernard\Envelope.
    • Service methods does not prepend on anymore. onSendNewsletter would be sendNewsletter.
    • Remove Invoker Object. Instead this functionality have been moved into the Consumer which implements Middleware.
    • Remove Middleware from Queue. Instead the Producer implements Middleware.
    • Producer takes a Queue name as the second parameter.
    • Replace ServiceResolver with Router and migrate the old Pimple and Container ServiceResolver's
    Source code(tar.gz)
    Source code(zip)
  • 0.9.2(Sep 18, 2013)

  • 0.9.1(Sep 10, 2013)

  • 0.9.0(Sep 10, 2013)

    • Support any callable in ObjectResolver
    • Implement Middleware. Middleware is used by the Consumer and Producer when a Message in queued or consumed.
    • Removed Spork support until it can be reimplemented as a Middleware.
    • Add LoggerMiddleware and ErrorLogMiddleware for basic logging when producing and consuming messages.
    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(Aug 2, 2013)

    • Service resolvers now resolve to a callable. This allows for closures to do work.
    • Consumer is now responsible for creating Invoker object.
    • Spork return a Proxy object that allows calling the right method on service object.
    • New schema for DoctrineDriver. Queues are now kept in a seperate table.
    • ObjectResolver now supports object instances and class names. Laravel can then register facades.
    • ServiceResolvers now takes an optional array of array('MessageName' => $service).
    Source code(tar.gz)
    Source code(zip)
  • 0.7.1(Jul 12, 2013)

  • 0.7.0(Jul 12, 2013)

    • Add ProduceCommand by @ukautz.
    • Refactor examples in example directory to remove ugly code.
    • BC Break. Rename Invocator to Invoker as the former is not a word.
    • New NaiveSerializer with no dependencies.
    • Fixed error in DoctrineDriver wheen peeking.
    Source code(tar.gz)
    Source code(zip)
  • 0.6.1(Jul 3, 2013)

    • Increment sleep in drivers that does not natively support internal to minimize CPU usage.
    • Fix error in $queueUrls for SQS Driver where aliased queue urls would show up.
    • Include documentation for the new drivers and options. @ukautz
    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Jul 3, 2013)

    • Add driver for Amazon SQS @ukautz
    • Add driver for Iron MQ @ukautz
    • Add driver for Doctrine DBAL which brings support for major SQL backends.
    • Implement acknowledge logic for messages and drivers that uses it. @ukautz
    • Add prefetching for drivers that use slow endpoints and supports getting more than one message.
    • Refactor Consumer and cover it with tests.
    • Drop using mocks where appropiate and instead use InMemoryQueue and InMemoryFactory
    • Remove example/in_memory.php.
    • Bring consistency by using Envelope internally and Message externally (end user).
    Source code(tar.gz)
    Source code(zip)
PHP Library that implements several messaging patterns for RabbitMQ

Thumper Thumper is a PHP library that aims to abstract several messaging patterns that can be implemented over RabbitMQ. Inside the examples folder yo

php-amqplib 276 Nov 20, 2022
The most widely used PHP client for RabbitMQ

php-amqplib This library is a pure PHP implementation of the AMQP 0-9-1 protocol. It's been tested against RabbitMQ. The library was used for the PHP

php-amqplib 4.2k Jan 6, 2023
PHP client for beanstalkd queue

Pheanstalk Next (5) The master branch will be a WIP branch for v5 of this library until it is released. If any patches are needed in v4 they should be

null 1.9k Dec 21, 2022
PHP bindings for Tarantool Queue.

Tarantool Queue Tarantool is a NoSQL database running in a Lua application server. It integrates Lua modules, called LuaRocks. This package provides P

Tarantool PHP 62 Sep 28, 2022
Message Queue, Job Queue, Broadcasting, WebSockets packages for PHP, Symfony, Laravel, Magento. DEVELOPMENT REPOSITORY - provided by Forma-Pro

Supporting Enqueue Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and

Enqueue 2.1k Dec 22, 2022
PHP client for beanstalkd queue

Pheanstalk Pheanstalk is a pure PHP 7.1+ client for the beanstalkd workqueue. It has been actively developed, and used in production by many, since la

null 1.9k Dec 21, 2022
PHP-Queue: A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners.

A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners. Why PHP-Queue? Implementing a

CoderKungfu 646 Dec 30, 2022
php-vips is a binding for libvips 8.7 and later that runs on PHP 7.4 and later

PHP binding for libvips php-vips is a binding for libvips 8.7 and later that runs on PHP 7.4 and later. libvips is fast and needs little memory. The v

libvips 411 Jan 8, 2023
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.7k Jan 4, 2023
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.7k Dec 30, 2022
Termage provides a fluent and incredibly powerful object-oriented interface for customizing CLI output text color, background, formatting, theming and more.

Termage provides a fluent and incredibly powerful object-oriented interface for customizing CLI output text color, background, formatting, theming and

TERMAGE 75 Dec 20, 2022
Takes in a HEX color and produces variations of that colour for the foreground and background

css-colors Takes in a HEX color and produces variations of that colour for the foreground and background It takes a great php class made by Patrick Fi

Soapbox Innovations Inc. 9 Jul 24, 2020
Create beautiful generative background images from a string. Based on jasonlong/geo_pattern

GeoPattern This is a PHP port of jasonlong/geo_pattern. Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a

Redeye Group 106 Aug 17, 2022
Backwards compatibility Extension and Library for PHP 8.x and later

colopl_bc Provides various compatibility functions required for PHP (temporary) migration. WARNING This extension is intended for temporary use only.

COLOPL,Inc. 10 Jun 13, 2023
Melek Berita Backend is a service for crawling data from various websites and processing the data to be used for news data needs.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Chacha Nurholis 2 Oct 9, 2022
All about docker projects either from dockerfile or compose. Anyway, here the project is in the form of a service, for the programming language I will make it later

Docker Project by ItsArul Hey, yo guys okay, this time I made some projects from Docker. Anyway, this project is open source, for example, if you want

Kiyo 10 Nov 4, 2022
Allow any Discord user to sign in to your website and save their discord user information for later use.

Simple Discord SSO ( Single Sign-On ) Requires at least: 5.0 Tested up to: 5.8.3 Stable tag: 1.0.2 Requires PHP: 7.4 License: GPLv2 or later License U

null 2 Oct 7, 2022
Disclaimer: The documentation of this plugin is English at the moment, but I might go for Latin later down the line, just for the fun of it.

Quiritibus Plugin This repository is storing the custom plugin developed for the Quiritibus Latin Magazine website, currently being developed at: http

Alkor András 1 Jan 19, 2022
Save items in a bucket, retrieve them later.

Bucket Save items in a bucket, retrieve them later. use Laragear\Bucket\Facades\Buckets; use App\Models\Message; public function send(Message $messag

Laragear 2 Jun 3, 2022
Full-featured e-commerce platform with multi-domain and multi-language support for PHP 8

Surikata.io Full-featured e-commerce platform with multi-domain and multi-language support for PHP 8. Free to use for both commercial and personal pro

null 8 Apr 5, 2022