{"id":17213347,"url":"https://github.com/pielonet/concurrency","last_synced_at":"2025-09-03T00:31:30.426Z","repository":{"id":180152653,"uuid":"430414047","full_name":"pielonet/concurrency","owner":"pielonet","description":"PHP/parallel programming tutorial and examples","archived":false,"fork":false,"pushed_at":"2024-10-13T07:48:58.000Z","size":123,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-08T01:18:59.233Z","etag":null,"topics":["parallel-programming","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pielonet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-11-21T16:06:07.000Z","updated_at":"2024-10-14T06:54:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"75719c02-971c-42fd-ad66-d13af9d0fce3","html_url":"https://github.com/pielonet/concurrency","commit_stats":null,"previous_names":["pielonet/concurrency"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pielonet%2Fconcurrency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pielonet%2Fconcurrency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pielonet%2Fconcurrency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pielonet%2Fconcurrency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pielonet","download_url":"https://codeload.github.com/pielonet/concurrency/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231819014,"owners_count":18431233,"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":["parallel-programming","php"],"created_at":"2024-10-15T03:01:08.054Z","updated_at":"2024-12-30T05:47:52.081Z","avatar_url":"https://github.com/pielonet.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# concurrency\nPHP parallel programming tutorial and examples using [php/parallel](https://www.php.net/manual/en/book.parallel.php) extension\n\n- Comparison between single and multiple waiting queues (at post office...)\n- PHP/parallel optimized run examples\n- Step by step tutorial with exercises and solutions\n\n## How to run examples\n\n- [Install Docker](https://docs.docker.com/engine/install/)\n\n- Run a script e.g simulateQueue.php (may take much time on the first run since the Docker container is being build)\n```bash\n./run.sh -b simulateQueue/main.php\n```\n\nCommand options :\n- -b \n    Builds container. This option MUST be used on first run ! It is optional afterwards.\n- -i [official|frankenphp]\n     Whether to use the offical PHP Docker image or that of FrankenPHP project. Defaults to \"official\"\n- -d `\u003cDocker-options\u003e`\n    Set specific Docker/run options. Useful to control CPU or memory use by Docker. Defaults to \"--cpus=2.0\".\n\n### Scripts\n\n- `simulateQueue` : compare single and multiple queues average and max waiting time. The queues are implemented as sequential programs. Multiple simulations ar run in parallel.\n- `lib/Pool.php` : a simple \"Pool\" class to run any number of tasks in parallel with a defined concurrency. Can be reused in any project !\n\n### Tutorial\n\nExample are ordered by difficulty, starting with very easy examples.\n\nEach examples/X (where X stands for the number of the example) can be run with the following command :\n```bash\n./run.sh -b tutorial/example/X/main.php\n```\n\n\n- `1` : \"zzz !\", Run two simple tasks in parallel\n- `2` : \"Molière !\" Run many tasks in parallel with arguments\n- `3` : \"Alice is having a snap !\", Future object and return value\n- `4` : \"Alice and Bob sleep simultaneously\", Get Future return value as soon as it completes\n- `5` : \"multiple sleepers in limited number of rooms\", Launch tasks in parallel in a limited number of threads and wait for them to complete\n- `6` : \"http only !\", Parallel download with Guzzle 7\n- `7` : \"SSH the PHP way ! \", Parallel SSH with SSH2 extension\n- `8` : \"generic !\", Parallel SSH as exec shell command and generic concurrency class\n- `9` : \"Pong...zzz!\", Run two simple tasks in parallel and synchronize them with a channel\n- `10` : Single queue parallel simulation\n- `11` : Multiple queues parallel simulation\n- `12` : Parallel thread launched from a parallel thread\n- `42` : Benchmark single and multiple queues in parallel\n- `100` : Data-flow : create an adder waiting from two parallel channels to make an addition\n- `101` : Prime sieve with daisy-chain filter processes compared to sequential algorithm\n- `102` : Fibonacci : Mimics the Go \"select\" statement with event-loop\n\n## Utils (Linux)\n\n- Get number of threads for your process\n```bash\nps -o thcount \u003cpid\u003e\n```\n\n- Monitor context switches per second : watch \"cs\" value\n```bash\nvmstat 1\n```\n\n## Links\n\n- [PHP/parallel repository](https://github.com/krakjoe/parallel)\n- [A more complex parallel example: a Web crawler by Joe Watkins aka Krakjoe](https://gist.github.com/krakjoe/0ee02b887288720d9b785c9f947f3a0a)\n\n## Fund php/parallel\n\n[![GoFundMe](https://img.shields.io/badge/GoFundMe-00B964.svg?style=for-the-badge\u0026logo=GoFundMe\u0026logoColor=white)](https://gofund.me/c34f3dde)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpielonet%2Fconcurrency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpielonet%2Fconcurrency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpielonet%2Fconcurrency/lists"}