Download the PHP package misterion/ko-worker without Composer

On this page you can find all versions of the php package misterion/ko-worker. 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 ko-worker

ko-worker

Build Status Latest Stable Version Code Coverage Scrutinizer Code Quality Latest Unstable Version License

About

Ko-worker project is a PHP library that aims to abstract queue and RPC messaging patterns that can be implemented over RabbitMQ. The other goal is simplify message dispatching and RPC server development over RabbitMQ.

Each time you starting to use something like queues you should decide how to process your messages. Yes, it's sounds not complicated:

And Ko-Worker allows to simplify this to just 2 steps

Why Ko-worker?

Requirements

PHP >= 5.4
pcntl extension installed
posix extension installed
amqp extension installed

Installation

Composer

The recommended way to install library is composer. You can see package information on Packagist.

Do not use composer?

Just clone the repository and take care about autoload for namespace Ko.

Examples

Look at examples folder

UNDONE

Usage

First of all your should create your RabbitMq configuration file. For example config.yaml:

Here we configure the exchange producer and queue consumer that our application will have. In this example Ko\AmqpBroker will contain the producer social_activity and consumer named social_activity.

You should specify a connection for the client.

If you need to add optional queue or exchange arguments, then your options can be something like this:

another example with message TTL of 20 seconds:

The argument value must be a list of datatype and value. Valid datatypes are:

Adapt the arguments according to your needs.

If you want to bind queue with specific routing keys you can declare it in producer or consumer config:

Producers, Consumers, AqmBroker?

In a messaging application, the process sending messages to the broker is called producer while the process receiving those messages is called consumer. In your application you will have several of them that you can list under their respective entries in the configuration.

Producer

A producer will be used to send messages to the server. In the AMQP Model, messages are sent to an exchange, this means that in the configuration for a producer you will have to specify the connection options along with the exchange options, which usually will be the name of the exchange and the type of it.

Now let's say that you want to process some social network activity in the background. After you add friend, you will publish a message to server with the following information:

Besides the message itself, the Ko\RabbitMq\Producer#publish() method also accepts an optional routing key parameter and an optional array of additional properties. This way, for example, you can change the application headers.

The next piece of the puzzle is to have a consumer that will take the message out of the queue and process it accordingly.

Consumers

A consumer will connect to the server and start a loop waiting for incoming messages to process. Depending on the specified class for such consumer will be the behavior it will have. Let's review the consumer configuration from above:

As we see there, the class option has a reference to an \MyProject\TestAction class. It should implements Ko\Worker\ActionInterface.

When the consumer gets a message from the server it will create and execute such class. If for testing or debugging purposes you need to specify a different class, then you can change it there.

Apart from the callback we also specify the connection to use, the same way as we do with a producer. The remaining options are the the queue_options. In the queue_options we will provide a queue name and binding.

Why?

As we said, messages in AMQP are published to an exchange. This doesn't mean the message has reached a queue. For this to happen, first we need to create such queue and then bind it to the exchange.

The cool thing about this is that you can bind several queues to one exchange, in that way one message can arrive to several destinations.

The advantage of this approach is the decoupling from the producer and the consumer. The producer does not care about how many consumers will process his messages.

All it needs is that his message arrives to the server. In this way we can expand the actions we perform every time a friend added without the need to change code in our controller.

Now, how to run a consumer? There's a command for it that can be executed like this:

What does this mean?

We are executing the social_activity consumer telling it should use 10 child process to consuming.

Every time the consumer receives a message from the server, it will execute the configured callback passing the AMQP message as an instance of the AMQPEnvelope class. The message body can be obtained by calling $msg->getBody().

By default the consumer will process messages in an endless loop for some definition of endless.

UNDONE

Production

Ko-worker came with nice ko-package utility which allow you to create executable phar from your worker project.

Credits

Ko-worker written as a part of GameNet project by Nikolay Bondarenko (misterionkell at gmail.com) and Vadim Sabirov (pr0head at gmail.com). We use some interesting ideas from Alvaro Videla Thumper and part of documentation from RabbitMqBundle.

License

Released under the MIT license.

Links


All versions of ko-worker with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
misterion/ko-process Version ~0.4
symfony/yaml Version ^3.0
ulrichsg/getopt-php Version ~3.1.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 misterion/ko-worker contains the following files

Loading the files please wait ....