Download the PHP package tomaj/hermes without Composer

On this page you can find all versions of the php package tomaj/hermes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hermes

Hermes

Background job processing PHP library

Scrutinizer Code Quality Latest Stable Version Phpstan

What is Hermes?

If you need to process some task outside of HTTP request in your web app, you can utilize Hermes. Hermes provides message broker for sending messages from HTTP thread to offline processing jobs. Recommended use for sending emails, call other API or other time-consuming operations.

Another goal for Hermes is variability to use various message brokers like Redis, rabbit, database, and ability to easily create new drivers for other messaging solutions. And also the simple creation of workers to perform tasks on specified events.

Installation

This library requires PHP 7.2 or later.

The recommended installation method is via Composer:

Library is compliant with PSR-1, PSR-2, PSR-3 and PSR-4.

Optional dependencies

Hermes is able to log activity with a logger that is compatible with psr/log interface. For more information take a look at psr/log.

The library works without logger, but maintainer recommends installing monolog for logging.

Supported drivers

Right now Hermes library is distributed with 3 drivers and one driver in a separate package:

Note: You have to install all 3rd party libraries for initializing connections to these drivers. For example, you have to add nrk/predis to your composer.json and create a connection to your Redis instance.

Concept - How Hermes works?

Hermes works as an emitter and Dispatcher for events from your PHP requests on the webserver to particular handler running on CLI. Basically like this:

You have to implement these four steps in your application:

  1. select driver that you would like to use and register it to Dispatcher and Emitter
  2. emit events when you need to process something in the background
  3. write a handler class that will process your message from 2.
  4. create a PHP file that will run on your server "forever" and run Dispatcher there

How to use

This simple example demonstrates using Redis driver and is an example of how to send email in the background.

Emitting event

Emitting messages (anywhere in the application, easy and quick).

Processing event

For processing an event, we need to create some PHP file that will be running in CLI. We can make this simple implementation and register this simple handler.

For running handler.php on your server you can use tools like upstart, supervisord, monit, god, or any other alternative.

Logging

Hermes can use any psr/log logger. You can set logger for Dispatcher or Emitter and see what type of messages come to Dispatcher or Emitter and when a handler processed a message. If you add trait Psr\Log\LoggerAwareTrait (or implement Psr\Log\LoggerAwareInterface) to your handler, you can use logger also in your handler (Dispatcher and Emitter injects it automatically).

Basic example with monolog:

and if you want to log also some information in handlers:

Retry

If you need to retry, you handle() method when they fail for some reason you can add RetryTrait to the handler. If you want, you can override the maxRetry() method from this trait to specify how many times Hermes will try to run your handle(). Warning: if you want to use retry you have to use a driver that supports delayed execution ($executeAt message parameter)

Priorities

There is a possibility to declare multiple queues with different priority and ensure that messages in the high priority queue will be processed first.

Example with Redis driver:

Few details:

Graceful shutdown

Hermes worker can be gracefully stopped.

If implementation of Tomaj\Hermes\Shutdoown\ShutdownInteface is provided when initiating Dispatcher, Hermes will check ShutdwnInterface::shouldShutdown() after each processed message. If it returns true, Hermes will shutdown (notice is logged).

WARNING: relaunch is not provided by this library, and it should be handled by process controller you use to keep Hermes running (e.g. launchd, daemontools, supervisord, etc.).

Currently, two methods are implemented.

SharedFileShutdown

Shutdown initiated by touching predefined file.

RedisShutdown

Shutdown initiated by storing timestamp to Redis to predefined shutdown key.

Scaling Hermes

If you have many messages that you need to process, you can scale your Hermes workers very quickly. You just run multiple instances of handlers - CLI files that will register handlers to Dispatcher and then run $dispatcher->handle(). You can also put your source codes to multiple machines and scale it out to as many nodes as you want. But it would help if you had a driver that supports these 2 things:

  1. driver needs to be able to work over the network
  2. one message must be delivered to only one worker

If you ensure this, Hermes will work correctly. Rabbit driver or Redis driver can handle this stuff, and these products are made for big loads, too.

Extending Hermes

Hermes is written as separate classes that depend on each other via interfaces. You can easily change the implementation of classes. For example, you can create a new driver, use another logger. Or if you really want, you can create the format of your messages that will be sent to your driver serialized via your custom serializer.

How to write your driver

Each driver has to implement Tomaj\Hermes\Driver\DriverInterface with 2 methods (send and wait). A simple driver that will use Gearman as a driver

How to write your own serializer

If you want o use your own serializer in your drivers, you have to create a new class that implements Tomaj\Hermes\MessageSerializer, and you need a driver that will support it. You can add the trait Tomaj\Hermes\Driver\SerializerAwareTrait to your driver that will add method setSerializer to your driver.

Simple serializer that will use library jms/serializer:

Scheduled execution

From version 2.0 you can add the 4th parameter to Message as a timestamp in the future. This message will be processed after this time. This functionality is supported in RedisSetDriver and PredisSetDriver right now.

Upgrade

From v3 to v4

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

Contributing

Please see CONDUCT for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

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


All versions of hermes with dependencies

PHP Build Version
Package Version
Requires php Version >= 7.2.0
ext-json Version *
ramsey/uuid Version ^3 || ^4
psr/log Version ^1 || ^2 || ^3
tracy/tracy Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tomaj/hermes contains the following files

Loading the files please wait ....