{"id":20795657,"url":"https://github.com/graze/parallel-process","last_synced_at":"2025-04-06T04:10:55.475Z","repository":{"id":21915984,"uuid":"94424167","full_name":"graze/parallel-process","owner":"graze","description":":running: Run multiple processes simultaneously","archived":false,"fork":false,"pushed_at":"2022-06-01T07:51:16.000Z","size":137,"stargazers_count":103,"open_issues_count":8,"forks_count":23,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-30T03:04:40.632Z","etag":null,"topics":["console","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/graze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-15T09:35:03.000Z","updated_at":"2023-06-02T15:04:09.000Z","dependencies_parsed_at":"2022-08-07T10:01:20.380Z","dependency_job_id":null,"html_url":"https://github.com/graze/parallel-process","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fparallel-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fparallel-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fparallel-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fparallel-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graze","download_url":"https://codeload.github.com/graze/parallel-process/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430870,"owners_count":20937874,"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":["console","parallel","php","process"],"created_at":"2024-11-17T16:23:09.268Z","updated_at":"2025-04-06T04:10:55.257Z","avatar_url":"https://github.com/graze.png","language":"PHP","readme":"# Parallel Process\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/graze/parallel-process.svg?style=flat-square)](https://packagist.org/packages/graze/parallel-process)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/graze/parallel-process/master.svg?style=flat-square)](https://travis-ci.org/graze/parallel-process)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/graze/parallel-process.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/parallel-process/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/graze/parallel-process.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/parallel-process)\n[![Total Downloads](https://img.shields.io/packagist/dt/graze/parallel-process.svg?style=flat-square)](https://packagist.org/packages/graze/parallel-process)\n\nRun multiple `Symfony\\Process`'s at the same time.\n\n[![giphy](https://static.tumblr.com/490f5829d7bf754914a01e5d20de30f3/x0oab7z/i9Ro70j5c/tumblr_static__640_v2.gif)]()\n\n## Install\n\nVia Composer\n\n```bash\n$ composer require graze/parallel-process\n```\n\nIf you want to use Tables or Lines to output to the console, include:\n\n```bash\n$ composer require graze/console-diff-renderer\n```\n\n## Usage\n\n``` php\n$pool = new Pool();\n$pool-\u003eadd(new Process('sleep 100'));\n$pool-\u003eadd(new Process('sleep 100'));\n$pool-\u003eadd(new Process('sleep 100'));\n$pool-\u003eadd(new Process('sleep 100'));\n$pool-\u003eadd(new ProcessRun(new Process('sleep 100')));\n$pool-\u003erun(); // blocking that will run till it finishes\n```\n\nA Pool will run all child processes at the same time.\n\n### Priority Pool\n\nA Priority pool will sort the runs to allow a prioritised list to be started. You can also limit the number of \nprocesses to run at a time.\n\n```php\n$pool = new PriorityPool();\n$pool-\u003eadd(new Process('sleep 100'), [], 1);\n$pool-\u003eadd(new Process('sleep 100'), [], 0.1);\n$pool-\u003eadd(new Process('sleep 100'), [], 5);\n$pool-\u003eadd(new Process('sleep 100'), [], 10);\n$pool-\u003eadd(new CallbackRun(\n    function () {\n        return 'yarp';\n    },\n    [],\n    2\n);\n$pool-\u003erun(); // blocking that will run till it finishes\n```\n\n### Recursive Pools\n\nYou can add a Pool as a child to a parent pool. A Pool will act just like a standard run and hide the child runs.\n\nIf the parent is a PriorityPool, it will control all the child runs so that priorities and the max simultaneous\nconfiguration options still apply.\n\n```php\n$pool = new Pool();\n$pool-\u003eadd(new Process('sleep 100'));\n$pool2 = new Pool();\n$pool2-\u003eadd(new Process('sleep 100'));\n$pool-\u003eadd($pool2);\n$pool-\u003erun(); // blocking that will run till it finishes\n```\n\n### Display\n\nYou can output runs in a few different ways to the command line. These require the use of the package:\n[`graze/console-diff-renderer`](https://github.com/graze/console-diff-renderer).\n\n#### Table\n\nVisual output of the parallel processes\n\n```php\n$pool = new \\Graze\\ParallelProcess\\PriorityPool();\nfor ($i = 0; $i \u003c 5; $i++) {\n    $time = $i + 5;\n    $pool-\u003eadd(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' =\u003e $time]);\n}\n$output = new \\Symfony\\Component\\Console\\Output\\ConsoleOutput();\n$table = new \\Graze\\ParallelProcess\\Display\\Table($output, $pool);\n$table-\u003erun();\n```\n\n[![asciicast](https://asciinema.org/a/55r0rf9zin49s751j3a8zbdw1.png)](https://asciinema.org/a/55r0rf9zin49s751j3a8zbdw1)\n\n#### Lines\n\nWrite the output of each process to the screen\n\n```php\n$pool = new \\Graze\\ParallelProcess\\PriorityPool();\n$pool-\u003esetMaxSimultaneous(3);\nfor ($i = 0; $i \u003c 5; $i++) {\n    $time = $i + 5;\n    $pool-\u003eadd(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]);\n}\n$output = new \\Symfony\\Component\\Console\\Output\\ConsoleOutput();\n$lines = new \\Graze\\ParallelProcess\\Display\\Lines($output, $pool);\n$lines-\u003erun();\n```\n\n[![asciicast](https://asciinema.org/a/Zpr1JhGTxmsoDXBFRjsRek4wt.png)](https://asciinema.org/a/Zpr1JhGTxmsoDXBFRjsRek4wt)\n\n## Testing\n\n``` bash\n$ make test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email security@graze.com instead of using the issue tracker.\n\n## Credits\n\n- [Harry Bragg](https://github.com/h-bragg)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraze%2Fparallel-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraze%2Fparallel-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraze%2Fparallel-process/lists"}