Skip to content

Repository files navigation

Utopia Queue

Important

This repository is a read-only mirror of the utopia-php monorepo. Development happens in packages/queue — please open issues and pull requests there.

Total DownloadsDiscord

Utopia Queue is a powerful Queue library. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.

Although this library is part of the Utopia Framework project it is dependency free and can be used as standalone with any other PHP project or framework.

Getting started

Install using Composer:

composer require utopia-php/queue

Init in your application:

<?phprequire_once__DIR__ . '/../../vendor/autoload.php';
// Create a worker using the Swoole adapteruseUtopia\Queue;
useUtopia\Queue\Message;
$connection = newQueue\Connection\Redis('redis');
if ($connection->ping()) {
var_dump('Connection is ready.');
} else {
var_dump('Connection is not ready.');
}
$adapter = newQueue\Adapter\Swoole($connection, 12, 'my-queue');
$server = newQueue\Server($adapter);
$server
->job()
->inject('message')
->action(function (Message$message) {
var_dump($message);
});
$server
->error()
->inject('error')
->action(function ($error) {
echo$error->getMessage() . PHP_EOL;
});
$server
->workerStart()
->action(function () {
echo"Worker Started" . PHP_EOL;
});
$server->start();
// Enqueue messages to the worker using the Redis adapter$connection = newRedis('redis', 6379);
$client = newClient('my-queue', $connection);
$client->enqueue([
'type' => 'test_number',
'value' => 123
]);

System requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

About

No description or website provided.

Topics

Resources

Stars

11 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages