PHPackages                             white-rabbit-1-sketch/php-worker-pool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. white-rabbit-1-sketch/php-worker-pool

ActiveLibrary[Queues &amp; Workers](/categories/queues)

white-rabbit-1-sketch/php-worker-pool
=====================================

A lightweight PHP library to manage a pool of workers for parallel task execution. This library allows you to easily manage worker threads, process tasks concurrently, and optimize your application’s performance by executing multiple tasks in parallel. Ideal for background jobs, batch processing.

1.0.0(1y ago)16MITPHPPHP ^8.1

Since Oct 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/white-rabbit-1-sketch/php-worker-pool)[ Packagist](https://packagist.org/packages/white-rabbit-1-sketch/php-worker-pool)[ RSS](/packages/white-rabbit-1-sketch-php-worker-pool/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

PHP Worker Pool
===============

[](#php-worker-pool)

[![Latest Version](https://camo.githubusercontent.com/d1f331732d050f556010905b85f7e84adc492cccded534e7ddfc6cb8f7da2fbe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f77686974652d7261626269742d312d736b657463682f7068702d776f726b65722d706f6f6c)](https://camo.githubusercontent.com/d1f331732d050f556010905b85f7e84adc492cccded534e7ddfc6cb8f7da2fbe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f77686974652d7261626269742d312d736b657463682f7068702d776f726b65722d706f6f6c)[![Phpunit](https://camo.githubusercontent.com/8d0abdd70a659db91427baa2023d5c7c1bea521c92b718f80273e4dbfca60fcf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77686974652d7261626269742d312d736b657463682f7068702d776f726b65722d706f6f6c2f2e676974687562253246776f726b666c6f7773253246706870756e69742e796d6c)](https://camo.githubusercontent.com/8d0abdd70a659db91427baa2023d5c7c1bea521c92b718f80273e4dbfca60fcf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77686974652d7261626269742d312d736b657463682f7068702d776f726b65722d706f6f6c2f2e676974687562253246776f726b666c6f7773253246706870756e69742e796d6c)[![codecov](https://camo.githubusercontent.com/db8e59b1dd11ff30bd33d94cf2dab2ab2ca4948fb46ecda42a411727f894c686/68747470733a2f2f636f6465636f762e696f2f67682f77686974652d7261626269742d312d736b657463682f7068702d776f726b65722d706f6f6c2f67726170682f62616467652e7376673f746f6b656e3d5634584e51394644454b)](https://codecov.io/gh/white-rabbit-1-sketch/php-worker-pool)

[![Banner](readme/assets/img/banner.png)](readme/assets/img/banner.png)

A lightweight PHP library for managing worker pools with shared memory and task queues using **System V Message Queues** and **Redis**.

Features
--------

[](#features)

- **System V Message Queues** for efficient inter-process communication.
- **Redis Queue** for scalable, networked message handling.
- Simple worker pool implementation using process forking.
- Supports closures and custom task implementations via `TaskInterface`.
- Graceful handling of blocking operations.
- Lightweight and optimized for CLI usage.
- Queue easily extendable: implement custom queues with any storage system (e.g., Redis, databases) by extending the `QueueInterface`.
- Task types are extendable: simply implement the `TaskInterface` to create custom task types.
- Two queue options: **SysV Message Queues** and **Redis Queue**.
- Two working modes: **Infinite Loop** and **Fixed Loop** (process tasks until the queue is empty).

⭐️ Star the Project
-------------------

[](#️-star-the-project)

If you found this project useful, please consider giving it a star! 🌟 Your support helps improve the project and motivates us to keep adding new features and improvements. Thank you! 🙏

Table of Contents
-----------------

[](#table-of-contents)

1. [Features](#features)
2. [Quick Start](#quick-start)
    - [Installation](#installation)
    - [Examples](#examples)
        - [SysV Queue (Infinite Loop)](#example-for-sys-v-queue-with-infinite-loop)
        - [Redis Queue (Infinite Loop)](#example-for-redis-queue-with-infinite-loop)
        - [SysV Queue (Fixed Loop)](#example-for-sys-v-queue-with-fixed-loop)
        - [Redis Queue (Fixed Loop)](#example-for-redis-queue-with-fixed-loop)
3. [Queue Types](#queue-types)
    - [SysV Message Queues](#1-sysv-message-queues)
    - [Redis Queue](#2-redis-queue)
    - [Creating Custom Queues](#3-creating-custom-queues)
4. [Modes of Operation](#modes-of-operation)
    - [Infinite Loop (Default)](#1-infinite-loop-default-mode)
    - [Fixed Loop](#2-fixed-loop)
5. [How It Works](#how-it-works)
    - [System V Queues](#key-features-of-system-v-message-queues)
    - [Queue Implementation](#queue-implementation)
6. [Who This Library Is For](#who-this-library-is-for)
    - [Why Choose This Library?](#why-choose-this-library)
    - [Use Cases](#use-cases)
    - [Comparison with Other Solutions](#comparison-with-other-solutions)
7. [Author and License](#author-and-license)

Quick Start
-----------

[](#quick-start)

Installation
------------

[](#installation)

To install the PHP Worker Pool library, use Composer:

1. If you haven't already, install [Composer](https://getcomposer.org/download/) on your system.
2. Run the following command to install the library:

```
composer require white-rabbit-1-sketch/php-worker-pool
```

### Examples

[](#examples)

Example for Sys V Queue with infinite loop:

```
