bingo-soft / concurrent

Concurrent programming constructs for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest Stable Version Minimum PHP Version License: MIT Scrutinizer Code Quality

Concurrent

Concurrent programming constructs for PHP

Installation

Install library, using Composer:

composer require bingo-soft/concurrent

Example 1

$pool = new DefaultPoolExecutor(3); //only three active processes in the pool
$task1 = new TestTask("task 1");
$task2 = new TestTask("task 2");
$task3 = new TestTask("task 3");
$task4 = new TestTask("task 4");
$task4 = new TestTask("task 5");

$pool->execute($task1);
$pool->execute($task2);
$pool->execute($task3);
$pool->execute($task4); //task for is waiting for an empty slot in the pool
$pool->execute($task5); //task for is waiting for an empty slot in the pool
$pool->shutdown(); //shutdown pool with all processes attached

Running tests

./vendor/bin/phpunit ./tests

Running docker container with examples

cd example
docker-compose build
docker-compose up

To test core usage, you can edit TestTask - change value 2000 in run method to 8000 and then run container again. When container is running check how cores are used - use top command, then press f and turn on p (Last used Cpu). You will see, that while container is running, different processor cores are used.

Dependencies

The library depends on Swoole extension

About

Concurrent programming constructs for PHP

License:MIT License


Languages

Language:PHP 99.7%Language:Dockerfile 0.3%Language:Shell 0.0%