{"id":15589564,"url":"https://github.com/sokil/php-concurrency-labs","last_synced_at":"2025-04-28T10:47:39.578Z","repository":{"id":66361238,"uuid":"135758731","full_name":"sokil/php-concurrency-labs","owner":"sokil","description":"PHP Concurency research","archived":false,"fork":false,"pushed_at":"2022-10-18T21:07:12.000Z","size":86,"stargazers_count":17,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T15:16:41.848Z","etag":null,"topics":["async","concurrency","coroutines","ipc","multitasking","mutex","php","php-async","php-concurrency","php-threads","reactphp","synchronization","threads"],"latest_commit_sha":null,"homepage":"https://sokil.github.io/php-concurrency-labs/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sokil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-01T20:04:53.000Z","updated_at":"2024-11-20T12:11:19.000Z","dependencies_parsed_at":"2023-02-22T12:46:14.985Z","dependency_job_id":null,"html_url":"https://github.com/sokil/php-concurrency-labs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-concurrency-labs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-concurrency-labs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-concurrency-labs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-concurrency-labs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sokil","download_url":"https://codeload.github.com/sokil/php-concurrency-labs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251298344,"owners_count":21567003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","concurrency","coroutines","ipc","multitasking","mutex","php","php-async","php-concurrency","php-threads","reactphp","synchronization","threads"],"created_at":"2024-10-02T23:02:43.405Z","updated_at":"2025-04-28T10:47:39.569Z","avatar_url":"https://github.com/sokil.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# PHP Concurrency\n\n* [Definitions](#definitions)\n* [Asynchronous code execution](#asynchronous-code-execution)\n    * [Event loop extensions](#event-loop-extensions)\n    * [Event loop frameworks](#event-loop-frameworks)\n      * [ReactPHP](#reactphp)\n      * [AMP](#amp)\n      * [icicleio](#icicleio) - deprecated in favor of [Amp v2.0](https://amphp.org)\n      * [Kraken](#kraken)\n      * [Workerman](#workerman)\n* [Multithread code execution](#multithread-code-execution)\n  * [Thread extensions](#thread-extensions)\n* [Coroutines](#coroutines)\n* [Distributed locking](#distributed-locking)\n* Inter-process communication\n   * [PCNTL Signals](http://php.net/manual/en/book.pcntl.php)\n   * [Socket](http://php.net/manual/en/book.sockets.php)\n   * Shared memory\n      * [Shmop](http://php.net/manual/en/book.shmop.php)\n      * [Semaphore](http://php.net/manual/en/book.sem.php) - Semaphore, Shared Memory and IPC\n      * [Sync](http://php.net/manual/en/book.sync.php) - Semaphore, Mutex, Shared Memory and IPC\n   * Mutex, Semaphore\n      * [Semaphore](http://php.net/manual/en/book.sem.php) - Semaphore, Shared Memory and IPC\n      * [Sync](http://php.net/manual/en/book.sync.php) - Semaphore, Mutex, Shared Memory and IPC\n   * [Named pipe](http://php.net/manual/ru/function.posix-mkfifo.php)\n   * [Expect](http://php.net/manual/en/book.expect.php) -  allows to interact with processes through PTY\n* [Process management](#process-management)\n* [Tools](#tools)\n     * External program execution\n       * [System program execution (PHP manual)](http://php.net/manual/en/book.exec.php)\n       * [popen (PHP manual)](http://php.net/manual/ru/function.popen.php)\n     * [POSIX](http://php.net/manual/en/book.posix.php) - process ids\n     * [Stream](#stream)\n     * [PHP sources](https://github.com/php)\n     * [Repositories related to the PHP Language](https://github.com/phplang)\n* RFC\n    * Fiber\n      * [RFC](https://wiki.php.net/rfc/fiber)\n      * [Source](http://fiberphp.org/) \n* [Articles](#articles)\n\n## Definitions\n\n[Concurrency](https://en.wikipedia.org/wiki/Concurrency_(computer_science)): ability of different parts of a program to be executed out-of-order.\n\n[Parallelism](https://en.wikipedia.org/wiki/Task_parallelism): Form of [parallel computing](https://en.wikipedia.org/wiki/Parallel_computing) in which execution of processes are carried out concurrently across multiple processors in parallel computing environments.\n\n[Multitasking](https://en.wikipedia.org/wiki/Computer_multitasking): is the concurrent execution of multiple tasks over a certain period of time. There are two types of multitasking:\n* [Co-operative, non-preemptive](https://en.wikipedia.org/wiki/Cooperative_multitasking):  is a style of computer multitasking when process voluntarily yield control and all programs must cooperate for the entire scheduling scheme to work.\n   * Asynchronous code execution\n   * Coroutines\n* [Preemptive](https://en.wikipedia.org/wiki/Preemption_(computing)#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.\n   * Threads\n   * Forks\n\n## Asynchronous code execution\n\n### Event loop extensions\n\n| Name | Extension | Source | Version | PHP version |\n| -----|-----------|--------|---------|-------------|\n| ext-libevent |[PHP Manual](http://php.net/manual/en/book.libevent.php) | [PECL](https://pecl.php.net/package/libevent), [git.php.net](http://git.php.net/?p=pecl/event/libevent.git) | 0.1.0 | \u003e= 5.3.0, \u003c 7.0.0 |\n| ext-event |[PHP Manual](http://php.net/manual/en/book.event.php) | [PECL](https://pecl.php.net/package/event), [Bitbucket](https://bitbucket.org/osmanov/pecl-event/src) | 2.3.0 | \u003e= 5.4, \u003e= 7.0 |\n| ext-libev |[GitHub manual](https://github.com/m4rw3r/php-libev/) | [GitHub](https://github.com/m4rw3r/php-libev) | | \u003c 7.0.0 |\n| ext-ev |[PHP Manual](http://php.net/manual/en/book.ev.php) | [PECL](https://pecl.php.net/package/ev), [BitBucket](https://bitbucket.org/osmanov/pecl-ev/src) | | \u003e= 5.4, \u003e 7.0 |\n| eio |[PHP Manual](http://php.net/manual/en/intro.eio.php)|[PECL](http://pecl.php.net/package/eio), [GitHub](https://github.com/rosmanov/pecl-eio)|||\n| swoole |[GitHub manual](https://github.com/swoole/swoole-src)|[GitHub](https://github.com/swoole/swoole-src)|||\n| libuv |[GitHub](https://github.com/bwoebi/php-uv)|[PECL](https://pecl.php.net/package/uv), [GitHub](https://github.com/bwoebi/php-uv)|||\n| concurent-php/ext-async | [GitHub manual](https://github.com/concurrent-php/ext-async) | [GitHub](https://github.com/concurrent-php/ext-async) | - | nightly | \n| ext-fiber | | https://wiki.php.net/rfc/fibers, https://github.com/amphp/ext-fiber | | |\n\nLinks:\n* [Benchmarking libevent against libev](http://libev.schmorp.de/bench.html) - libev faster\n\n#### ext-libevent\n\nHas build-in OpenSSL library, non-blocking IO, http, dns.\n\n```\npecl install libevent-0.1.0\n```\n\n#### ext-event\n\nEvent is a PECL extension providing interface to libevent C library.\n\nThe 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.\n\nDockerfile: https://github.com/sokil/php-concurrency-labs/blob/master/docker/Dockerfile.ext-event\n\n#### ext-libev\n\nLibrary tries to improve `libevent`. But this is only event library, instead of libevent giving non-blocking IO, http, etc.\n\nInstall `libev` library:\n\n```\nsudo apt-get install libev-dev\n```\n\nInstall php extension `ext-libev`. Clone https://github.com/m4rw3r/php-libev and build extension:\n\n```\nphpize\n./configure --with-libev\nmake\nmake install\n```\n\n#### libuv\n\n* [Official libuv site](http://libuv.org)\n* [Libuv source](https://github.com/libuv/libuv)\n\n### Event loop frameworks\n\n* [ReactPHP](#reactphp)\n* [AMP](#amp)\n* [icicleio](#icicleio)\n* [Kraken](#kraken)\n* [Workerman](#workerman)\n        \n#### ReactPHP\n\nSource: https://reactphp.org\n\nExamples: https://github.com/sokil/php-concurrency-labs/tree/master/src/ReactPHP\n\n```\ncd src/ReactPHP\nDocker build -t php-event .\ndocker run --rm -v `pwd`:/src php-event php /src/TimerExample.php\n```\n\n##### Articles\n\n* [Super Speed Symfony - ReactPHP](https://gnugat.github.io/2016/04/13/super-speed-sf-react-php.html)\n\n#### AMP\n\nSite: https://amphp.org\n\nSource: https://github.com/amphp\n\n#### icicleio\n\nIcicle is now deprecated in favor of [Amp v2.0](https://amphp.org)\n\nSource: https://github.com/icicleio\n\n#### Kraken\n\nSource: http://kraken-php.com\n\n#### Workerman\n\nSource: https://github.com/walkor/Workerman\n\n## Multithread code execution\n\n### Thread extensions\n\n|Name|Source|Manual|\n|----|------|------|\n|Pthreads|[GitHub](https://github.com/krakjoe/pthreads),[PECL](http://pecl.php.net/package/pthreads)|[PHP Manual](http://php.net/manual/ru/book.pthreads.php)|\n|Pht|[GitHub](https://github.com/tpunt/pht)|[PHP Manual](http://php.net/manual/en/book.pht.php)|\n\n#### Pthreads\n      \nDockerfile: https://github.com/sokil/php-concurrency-labs/blob/master/docker/Dockerfile.ext-phtreads\n\nExamples: https://github.com/sokil/php-concurrency-labs/tree/master/src/Pthreads\n\n## Coroutines\n\nCoroutines 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.\n\n### Articles\n\n* [Wikipedia](https://en.wikipedia.org/wiki/Coroutine)\n* [Cooperative multitasking using coroutines](https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html)\n* [Co-operative PHP Multitasking](https://medium.com/async-php/co-operative-php-multitasking-ce4ef52858a0)\n\n## Distributed locking\n\n* [Distributed lock manager (Wiki)](https://en.wikipedia.org/wiki/Distributed_lock_manager)\n* [Distributed locks with Redis](https://redis.io/topics/distlock)\n* Consul\n  * [CLI](https://www.consul.io/docs/commands/lock.html)\n  * API\n    * [Session](https://www.consul.io/api/session.html)\n    * [Semaphore](https://www.consul.io/docs/guides/semaphore.html)\n    * [KV Storage, aquiring](https://www.consul.io/api/kv.html)\n\n## Process management\n\n### Articles\n\n* [Bring High Performance Into Your PHP App (with ReactPHP)](http://marcjschmidt.de/blog/2014/02/08/php-high-performance.html)\n\n### Tools\n\n* PHP-PM\n  * GitHub: https://github.com/php-pm/php-pm\n* Spatie \n  * https://github.com/spatie/async\n\n## Tools\n\n### Stream\n\nPHP Manual: http://php.net/manual/ru/book.stream.php\n\nExamples: https://github.com/sokil/php-concurrency-labs/tree/master/src/Stream \n\n## Articles\n\n* [The Reactive Manifesto](https://www.reactivemanifesto.org/)\n* [Process Control Extensions (PHP Manual)](http://php.net/manual/en/refs.fileprocess.process.php)\n* [How to use the Linux AIO feature](https://github.com/littledan/linux-aio)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-concurrency-labs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsokil%2Fphp-concurrency-labs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-concurrency-labs/lists"}