PHP Classes

Taurus Publisher PHP Redis Client Library: Send jobs to a Redis server using LUA scripts

Recommend this page to a friend!
  Info   View files Example   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-11-30 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 14 All time: 11,184 This week: 87Up
Version License PHP version Categories
taurus-publisher-php 1.0Custom (specified...7.1Content management, Performance and o..., P...
Description 

Author

This package can queue and publish jobs in Redis using LUA scripts.

It can take as a parameter the details of a job as an array with the job properties and values.

The package can send the job to a queue managed by a Redis server using a script with commands defined in the LUA language.

Innovation Award
PHP Programming Innovation award nominee
December 2023
Nominee
Vote
Some tasks executed by computers may take a long time to complete due to the complexity of the task steps. When computer systems are under excessive load, those tasks may take a lot more time to finish.

That may happen when a user wants to publish an article in a blog system. Usually, that task requires creating and updating many database records.

When a system is under a lot of load, if multiple parallel tasks perform database access operations on the same tables, finishing all parallel tasks may take a lot of time.

Making users wait a long time for a computer task to finish is not a good idea because users may become irritated due to the lack of patience.

Using a queue management system may help avoid this problem. The long tasks are sent to a queue very quickly, and the user does not have to wait long. Later, the queue processing system may execute all queued tasks, one at a time, to avoid causing system overloading.

This package can queue tasks using a Redis server. It uses a script in LUA language to make the Redis server implement several steps of the queuing process on the Redis server site instead of doing those steps on the PHP Redis client side.

This package's capability minimizes the interactions between PHP and the Redis servers, thus making the job queueing faster.

Manuel Lemos
Picture of Leonardo Di Sarli
  Performance   Level  
Name: Leonardo Di Sarli <contact>
Classes: 10 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
TaurusPublisher\TaurusPublisher;

$queue = 'test';
$data = [
   
'publisher' => 'example',
];

$taurus = new TaurusPublisher();

print_r('Publish');
echo
PHP_EOL;

$result = $taurus->add(
   
$queue,
   
$data
);

print_r($result);
echo
PHP_EOL;


Details

PHP Taurus Queue Publisher

Latest Version codecov CI Build Downloads Old Downloads PRs Welcome Packagist License (custom server)

PHP library using LUA script to send for redis a job for Taurus queue

Installation

Release 7.0.0 Requires PHP 8.3

Release 6.0.0 Requires PHP 8.2

Release 5.0.0 Requires PHP 8.1

Release 4.0.0 Requires PHP 7.4

Release 3.0.0 Requires PHP 7.3

Release 2.0.0 Requires PHP 7.2

Release 1.0.0 Requires PHP 7.1

The recommended way to install is through Composer.

composer require not-empty/taurus-publisher-php-lib

Usage

Publishing

use TaurusPublisher\TaurusPublisher;
$queue = 'test';
$data = [
	'publisher' => 'example',
];
$taurus = new TaurusPublisher();
$result = $taurus->add(
    $queue,
    $data
);
var_dump($result);

Publishing with redis config

use TaurusPublisher\TaurusPublisher;
$queue = 'test';
$data = [
	'publisher' => 'example',
];
$redisConfig = [
    'scheme' => 'tcp',
    'host'   => 'localhost',
    'port'   => 6379,
];
$taurus = new TaurusPublisher($redisConfig);
$result = $taurus->add(
    $queue,
    $data
);
var_dump($result);

Publishing with queue config

use TaurusPublisher\TaurusPublisher;
$queue = 'test';
$data = [
	'publisher' => 'example',
];
$taurus = new TaurusPublisher();
$queueConfig = [
    'attempts' => 4,
    'backoff' => 20000,
    'delay' => 1,
    'removeOnComplete' => 20,
];
$result = $taurus->add(
    $queue,
    $data,
    $queueConfig
);
var_dump($result);

Publishing in loop without exceed redis connections (reuse redis connections)

you may pass a redis connection to persist connection and allow you to loop add method without overload redis with connections

use TaurusPublisher\TaurusPublisher;
use Predis\Client as Redis;
$redisConfig = [
    'scheme' => 'tcp',
    'host'   => 'redis',
    'port'   => 6379,
];
$client = new Redis($redisConfig);
$queue = 'test';
$data = [
	'publisher' => 'example',
];
$taurus = new TaurusPublisher(
    $redisConfig,
    [],
    $client
);
for ($i=0; $i < 1000000; $i++) { 
    $result = $taurus->add(
        $queue,
        $data
    );
    var_dump($result);
}

if you want an environment to run or test it, you can build and install dependences like this

docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/taurus-publisher-php-lib:php83 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/taurus-publisher-php-lib:php83 bash

Verify if all dependencies is installed

composer install --no-dev --prefer-dist

and run (you will need redis)

php sample/publisher-sample.php

Development

Want to contribute? Great!

The project using a simple code. Make a change in your file and be careful with your updates! Any new code will only be accepted with all validations.

To ensure that the entire project is fine:

First you need to building a correct environment to install all dependences

docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/taurus-publisher-php-lib:php83 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/taurus-publisher-php-lib:php83 bash

Install all dependences

composer install --dev --prefer-dist

Run all validations

composer check

Not Empty Foundation - Free codes, full minds


  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagecontrib (4 files)
Files folder imagesample (3 files)
Files folder imagesrc (2 files)
Files folder imagetests (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files  /  contrib  
File Role Description
  Accessible without login Plain text file coverage-checker.php Example Example script
  Accessible without login Plain text file Dockerfile Data Auxiliary data
  Accessible without login Plain text file pre-commit Data Auxiliary data
  Accessible without login Plain text file setup.sh Data Auxiliary data

  Files folder image Files  /  sample  
File Role Description
  Accessible without login Plain text file publisher-sample-with-queue-config.php Example Example script
  Accessible without login Plain text file publisher-sample-with-redis-config.php Example Example script
  Accessible without login Plain text file publisher-sample.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file RedisAddCommand.php Class Class source
  Plain text file TaurusPublisher.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file RedisAddCommandTest.php Class Class source
  Plain text file TaurusPublisherTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:14
This week:0
All time:11,184
This week:87Up