- Definitions
- Asynchronous code execution
- Multithread code execution
- Coroutines
- Distributed locking
- Inter-process communication
- PCNTL Signals
- Socket
- Shared memory
- Mutex, Semaphore
- Named pipe
- Expect - allows to interact with processes through PTY
- Process management
- Tools
- External program execution
- POSIX - process ids
- Stream
- PHP sources
- Repositories related to the PHP Language
- RFC
- Articles
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:
- Co-operative, non-preemptive: is a style of computer multitasking when process voluntarily yield control and all programs must cooperate for the entire scheduling scheme to work.
- Asynchronous code execution
- Coroutines
- Preemptive: involves the use of an interrupt mechanism which suspends the currently executing process and invokes a scheduler to determine which process should execute next. Therefore, all processes will get some amount of CPU time at any given time.
- Threads
- Forks
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:
- Benchmarking libevent against libev - libev faster
Has build-in OpenSSL library, non-blocking IO, http, dns.
pecl install libevent-0.1.0
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
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
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
Site: https://amphp.org
Source: https://github.com/amphp
Icicle is now deprecated in favor of Amp v2.0
Source: https://github.com/icicleio
Source: http://kraken-php.com
Source: https://github.com/walkor/Workerman
Name | Source | Manual |
---|---|---|
Pthreads | GitHub,PECL | PHP Manual |
Pht | GitHub | PHP Manual |
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 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.
- PHP-PM
- GitHub: https://github.com/php-pm/php-pm
- Spatie
PHP Manual: http://php.net/manual/ru/book.stream.php
Examples: https://github.com/sokil/php-concurrency-labs/tree/master/src/Stream