Download the PHP package mirays/codeigniter-queue-worker without Composer

On this page you can find all versions of the php package mirays/codeigniter-queue-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 codeigniter-queue-worker

CodeIgniter Queue Worker


CodeIgniter 3 Daemon Queue Worker Management Controller

License

This Queue Worker extension is collected into yidas/codeigniter-pack which is a complete solution for Codeigniter framework.

This library only provides worker controller, you need to implement your own queue driver with handler/process in it.

Features


OUTLINE


DEMONSTRATION

Running a listener (Daemon) with 2~5 workers setting added per 3 seconds:


INTRODUCTION

This library provides a Daemon Queue Worker total solution for Codeigniter 3 framework with Multi-Processes implementation, it includes Listener (Daemon) and Worker for processing new jobs from queue. You may integrate your application queue (such as Redis) with Queue Worker Controller.

PHP is a lack of support for multithreading at the core language level, this library implements multithreading by managing multiprocessing.

For more concepts, the following diagram shows the implementation structure of this library:

Listener (Daemon) could continue to run for detecting new jobs until it is manually stopped or you close your terminal. On the other hand , Worker could continue to run for processing new jobs until there is no job left, which the workers could be called by Listener.

Launcher is suitable for launching a listener process, which the running Listener process could be unique that the second launch would detect existent listener and do NOT launch again.


REQUIREMENTS

This library requires the following:


INSTALLATION

Run Composer in your Codeigniter project under the folder \application:

composer require yidas/codeigniter-queue-worker

Check Codeigniter application/config/config.php:

You could customize the vendor path into $config['composer_autoload']


CONFIGURATION

First, create a controller that extends the working controller, and then use your own queue driver to design your own handler to implement the worker controller. There are common interfaces as following:

These handlers are supposed to be designed for detecting the same job queue, but for different purpose. For example, if you are using Redis as message queue, Listener and Worker detect the same Redis list queue, Listener only do dispatching jobs by forking Worker, while Worker continue to takes out jobs and do the processing until job queue is empty.

How to Design a Worker

1. Build Initializer

The init() method is the constructor of worker controller, it provides you with an interface for defining initializartion such as Codeigniter library loading.

Example Code:

As above, myjobs library is defined by your own application which handles your job processes. Example code of myjobs with Redis

2. Build Worker

The handleWork() method is a processor for Worker that continue to take out jobs and do the processing. When this method returns false, that means the job queue is empty and the worker will close itself.

Example Code:

3. Build Listener

The handleListen() method is a processor for Listener that dispatches workers to handle jobs while it detects new job by returning true. When this method returns false, that means the job queue is empty and the listener will stop dispatching.

Example Code:

Porperties Setting

You could customize your worker by defining properties.

Public Properties

Property Type Deafult Description
$debug boolean true Debug mode
$logPath string null Log file path
$phpCommand string 'php' PHP CLI command for current environment
$listenerSleep integer 3 Time interval of listen frequency on idle
$workerSleep integer 0 Time interval of worker processes frequency
$workerMaxNum integer 4 Number of max workers
$workerStartNum integer 1 Number of workers at start, less than or equal to $workerMaxNum
$workerWaitSeconds integer 10 Waiting time between worker started and next worker starting
$workerHeathCheck boolean true Enable worker health check for listener

USAGE

There are 3 actions for usage:

You could run above actions by using Codeigniter 3 PHP-CLI command after configuring a Queue Worker controller.

Running Queue Worker

Worker

To process new jobs from the queue, you could simply run Worker:

As your worker processor handleWork(), the worker will continue to run (return true) until the job queue is empty (return false).

Listener

To start a listener to manage workers, you could simply run Listener:

As your listener processor handleListen(), the listener will dispatch workers when detecting new jobs (return true) until the job queue is empty with stopping dispatching and listening for next new jobs (return false).

Listener manage Workers by forking each Worker into running process, it implements Multi-Processes which could dramatically improve job queue performance.

Running in Background

This library supports running Listener or Worker permanently in the background, it provides you the ability to run Worker as service.

Launcher

To run Listener or Worker in the background, you could call Launcher to launch process:

By default, Launcher would launch listen process, you could also launch work by giving parameter:

Launcher could keep launching process running uniquely, which prevents multiple same listeners or workers running at the same time. For example, the first time to launch a listener:

Then, when you launch the listener again, Launcher would prevent repeated running:

For uniquely work scenario, you may use database as application queue, which would lead to race condition if there are multiple workers handling the same jobs. Unlike memcache list, database queue should be processed by only one worker at the same time.

Process Status

After launching a listener, you could check the listener service by command ps aux|grep php:

According to above, you could manage listener and workers such as killing listener by command kill 3129.

Workers would run while listener detected job, the running worker processes would also show in ps aux|grep php.

Manually, you could also use an & (an ampersand) at the end of the listener or worker to run in the background.


All versions of codeigniter-queue-worker with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
ext-posix Version *
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 mirays/codeigniter-queue-worker contains the following files

Loading the files please wait ....