{"id":29710670,"url":"https://github.com/fastbill/parallel-process-dispatcher","last_synced_at":"2025-07-23T21:39:20.120Z","repository":{"id":56989345,"uuid":"132821075","full_name":"fastbill/parallel-process-dispatcher","owner":"fastbill","description":"Tiny PHP library for running jobs in background and/or in parallel","archived":false,"fork":false,"pushed_at":"2020-02-29T18:24:30.000Z","size":42,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-04T14:37:52.783Z","etag":null,"topics":["async","concurrency","dispatcher","library","parallel","php","process"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastbill.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}},"created_at":"2018-05-09T22:56:13.000Z","updated_at":"2025-05-05T17:37:10.000Z","dependencies_parsed_at":"2022-08-21T09:10:32.413Z","dependency_job_id":null,"html_url":"https://github.com/fastbill/parallel-process-dispatcher","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/fastbill/parallel-process-dispatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbill%2Fparallel-process-dispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbill%2Fparallel-process-dispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbill%2Fparallel-process-dispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbill%2Fparallel-process-dispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastbill","download_url":"https://codeload.github.com/fastbill/parallel-process-dispatcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbill%2Fparallel-process-dispatcher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266753988,"owners_count":23979145,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","dispatcher","library","parallel","php","process"],"created_at":"2025-07-23T21:39:19.289Z","updated_at":"2025-07-23T21:39:20.105Z","avatar_url":"https://github.com/fastbill.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parallel-process-dispatcher [![Build Status](https://travis-ci.com/fastbill/parallel-process-dispatcher.svg?branch=master)](https://travis-ci.com/fastbill/parallel-process-dispatcher) [![Packagist](https://img.shields.io/packagist/dt/fastbill/parallel-process-dispatcher.svg)](https://packagist.org/packages/fastbill/parallel-process-dispatcher)\n\nThis micro-library has two classes. One encapsulates a (linux commandline) process into an object and allows asynchronous running without deadlocks. \nThe other is a multi-process-dispatcher which takes an arbitrary number of beforementioned processes and runs them simultaneously (with a maximum number of concurrent processes).\n\n### Usage examples:\n* Dispatching long running cronjobs which e.g. mostly wait for webservice responses (you can run more processes than\n  max. CPUs)\n* Running background workers which listen on a queue (maximum should be number of CPUs)\n* Running commandline-tasks inside a web application simultaneously, e.g. PDF-Generation, Image-Processing etc.\n\n\n### Installation:\n\nAdd the following to your `composer.json`:\n```js\n{\n    \"require\": {\n        \"fastbill/parallel-process-dispatcher\": \"*\"\n    }\n}\n```\n\nor just run the following command in your project root directory\n\n```sh\n$ composer require \"fastbill/parallel-process-dispatcher\"\n```\n\n## Usage\n\n### Classes\n\n#### Process\n\n```php\n$process = new Process('pngcrush --brute background.png');\n$process-\u003estart();\n\n// optional: do something else in your application\n\nwhile (! $process-\u003eisFinished() ) {\n    usleep(1000); //wait 1ms until next poll\n}\necho $process-\u003egetOutput();\n```\n\n#### Dispatcher\n\n```php\n$process1 = new Process('pngcrush --brute background.png');\n$process2 = new Process('pngcrush --brute welcome.png'); \n$process3 = new Process('pngcrush --brute logo.png'); \n\n$dispatcher = new Dispatcher(2);    // will make sure only two of those will actually run at the same time\n$dispatcher-\u003eaddProcess($process1);\n$dispatcher-\u003eaddProcess($process2);\n$dispatcher-\u003eaddProcess($process3);\n\n$dispatcher-\u003edispatch();  // this will run until all processes are finished.\n\n$processes = $dispatcher-\u003egetFinishedProcesses();\n\nforeach ($processes as $process) {\n    echo $process-\u003egetOutput(), \"\\n\\n\";\n}\n```\n\n### Advanced\n\n#### Using Process and Dispatcher to start multiple processes and later collect the results\n\n```php\n$dispatcher = new Dispatcher(2);\n\n$process1 = new Process('pngcrush --brute background.png');\n$dispatcher-\u003eaddProcess($process1, true);   // true starts the process if there are still free slots\n\n// [... more code ...]\n\n$process2 = new Process('pngcrush --brute welcome.png'); \n$dispatcher-\u003eaddProcess($process2, true);\n\n// [... more code ...]\n\n// during code execution, the dispatcher cannot remove finished processes from the stack, so you have to call the tick()-function\n// if you want the queue to advance - but it's optional since at latest the __destruct() function will call dispatch(); \n$dispatcher-\u003etick();\n\n// [... more code ...]\n\n$dispatcher-\u003edispatch();  // this will make the dispatcher wait until all the processes are finished, if they are still running\n\n$processes = $dispatcher-\u003egetFinishedProcesses();\n\n// loop over results\n```\n\n\n\n\n\n## Known Issues\n\n### Process\n\n* PHP Internals: Be aware that if the child process produces output, it will write into a buffer until the buffer is\nfull. If the buffer is full the child pauses until the parent reads from the buffer and makes more room. This is done\nin the isFinished() method. The dispatcher calls this method periodically to prevent a deadlock. If you use the process\nclass standalone, you have to possibilities to prevent this:\n  * call isFinished() yourself in either a loop, using a tick function or otherwise during execution of your script\n  * instead of writing to stdOut, divert output to a temporary file and use its name as output.\n  \n### Dispatcher\n\n* Multiple dispatchers (in different processes) are not aware of each other. So if you have a script that uses a\ndispatcher to call another script which itself uses a dispatcher to spawn multiple processes, you will end up with more\nchild processes than the maximum, so choose the maximum accordingly or use a queue (e.g. Redis) and make the workers\naware of each other by e.g. registering in a redis-stack for running workers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastbill%2Fparallel-process-dispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastbill%2Fparallel-process-dispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastbill%2Fparallel-process-dispatcher/lists"}