View on GitHub

php-concurrency-labs

PHP Concurency research

PHP Concurrency

Definitions

Concurrency: ability of different parts of a program to be executed out-of-order.

Parallelism: Form of parallel computing in which execution of processes are carried out concurrently across multiple processors in parallel computing environments.

Multitasking: is the concurrent execution of multiple tasks over a certain period of time. There are two types of multitasking:

Asynchronous code execution

Event loop extensions

Name Extension Source Version PHP version
ext-libevent PHP Manual PECL, git.php.net 0.1.0 >= 5.3.0, < 7.0.0
ext-event PHP Manual PECL, Bitbucket 2.3.0 >= 5.4, >= 7.0
ext-libev GitHub manual GitHub   < 7.0.0
ext-ev PHP Manual PECL, BitBucket   >= 5.4, > 7.0
eio PHP Manual PECL, GitHub    
swoole GitHub manual GitHub    
libuv GitHub PECL, GitHub    
concurent-php/ext-async GitHub manual GitHub - nightly
ext-fiber   https://wiki.php.net/rfc/fibers, https://github.com/amphp/ext-fiber    

Links:

ext-libevent

Has build-in OpenSSL library, non-blocking IO, http, dns.

pecl install libevent-0.1.0

ext-event

Event is a PECL extension providing interface to libevent C library.

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.

Dockerfile: https://github.com/sokil/php-concurrency-labs/blob/master/docker/Dockerfile.ext-event

ext-libev

Library tries to improve libevent. But this is only event library, instead of libevent giving non-blocking IO, http, etc.

Install libev library:

sudo apt-get install libev-dev

Install php extension ext-libev. Clone https://github.com/m4rw3r/php-libev and build extension:

phpize
./configure --with-libev
make
make install

libuv

Event loop frameworks

ReactPHP

Source: https://reactphp.org

Examples: https://github.com/sokil/php-concurrency-labs/tree/master/src/ReactPHP

cd src/ReactPHP
Docker build -t php-event .
docker run --rm -v `pwd`:/src php-event php /src/TimerExample.php
Articles

AMP

Site: https://amphp.org

Source: https://github.com/amphp

icicleio

Icicle is now deprecated in favor of Amp v2.0

Source: https://github.com/icicleio

Kraken

Source: http://kraken-php.com

Workerman

Source: https://github.com/walkor/Workerman

Multithread code execution

Thread extensions

Name Source Manual
Pthreads GitHub,PECL PHP Manual
Pht GitHub PHP Manual

Pthreads

Dockerfile: https://github.com/sokil/php-concurrency-labs/blob/master/docker/Dockerfile.ext-phtreads

Examples: https://github.com/sokil/php-concurrency-labs/tree/master/src/Pthreads

Coroutines

Coroutines are computer-program components that generalize subroutines for non-preemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.

Articles

Distributed locking

Process management

Articles

Tools

Tools

Stream

PHP Manual: http://php.net/manual/ru/book.stream.php

Examples: https://github.com/sokil/php-concurrency-labs/tree/master/src/Stream

Articles