{"id":21493648,"url":"https://github.com/milanowicz/php-thread","last_synced_at":"2025-03-17T11:42:02.704Z","repository":{"id":37052210,"uuid":"463965381","full_name":"milanowicz/php-thread","owner":"milanowicz","description":"Control processes in GNU/Linux systems by PHP","archived":false,"fork":false,"pushed_at":"2025-03-08T09:13:54.000Z","size":592,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T10:20:35.400Z","etag":null,"topics":["php","thread","thread-library","threads"],"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/milanowicz.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":"2022-02-26T21:00:14.000Z","updated_at":"2025-03-08T09:13:51.000Z","dependencies_parsed_at":"2025-02-11T19:22:42.304Z","dependency_job_id":"bd4f4d68-9989-4283-866a-90c9908c5da2","html_url":"https://github.com/milanowicz/php-thread","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-thread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-thread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-thread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-thread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milanowicz","download_url":"https://codeload.github.com/milanowicz/php-thread/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244029531,"owners_count":20386428,"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":["php","thread","thread-library","threads"],"created_at":"2024-11-23T15:43:50.722Z","updated_at":"2025-03-17T11:42:02.698Z","avatar_url":"https://github.com/milanowicz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Thread\n![Test](https://github.com/milanowicz/php-thread/workflows/Testing/badge.svg?branch=master)\n[![Mutation testing](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fmilanowicz%2Fphp-thread%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/milanowicz/php-thread/master)\n[![codecov](https://codecov.io/gh/milanowicz/php-thread/branch/master/graph/badge.svg?token=42G6ETI9NV)](https://codecov.io/gh/milanowicz/php-thread)\n\n![](https://img.shields.io/packagist/php-v/milanowicz/php-thread)\n![](https://img.shields.io/github/languages/top/milanowicz/php-thread)\n\n![](https://img.shields.io/github/v/tag/milanowicz/php-thread)\n![](https://img.shields.io/github/repo-size/milanowicz/php-thread)\n![](https://img.shields.io/github/languages/code-size/milanowicz/php-thread)\n\n![](https://img.shields.io/packagist/v/milanowicz/php-thread)\n![](https://img.shields.io/packagist/dt/milanowicz/php-thread)\n![](https://img.shields.io/packagist/dd/milanowicz/php-thread)\n![](https://img.shields.io/packagist/dm/milanowicz/php-thread)\n\n\nControl processes in GNU/Linux systems by this package for PHP 8.x\n\n\n## Usage\n\nInstall it by Composer\n\n```shell\n\u003e composer require milanowicz/php-thread\n```\n\n\nClass to control thread for one command\n\n```php\n$thread = new Milanowicz\\Thread\\Threads();\n$thread-\u003eexec('php scripts/script1.php');\n$thread-\u003eexec('php scripts/script2.php');\n$thread-\u003eanyRunning();\n$thread-\u003estopAll();\n$thread-\u003ereset();\n```\n\nWorker to run commands\n\n```php\n$worker = new Milanowicz\\Thread\\Worker([\n    'command' =\u003e '/bin/sleep 2',\n    'execMaxCounter' =\u003e 10, // How many would you execute?\n    'maxWorkers' =\u003e 2, // How process(es) should be started? \n    'maxExecutionTime' =\u003e 120, // Seconds to run php script\n    'memoryLimit' =\u003e '32M', // Maximum for php memory limit\n    'workerDelayStart' =\u003e 1, // Delay for starting processes after each other\n    'workerRunSleep' =\u003e 2, // Sleep to check again if enough processes are running\n]);\n$worker-\u003esetCheckDispatcher(function () { return \u003cbool\u003e; });\n$worker-\u003erun(); // Main call to start worker loop\n\n$worker-\u003egetThread(); // Get current Thread instance\n```\n\nSingleton to control it everywhere you like\n\n```php\n$singleton = new Milanowicz\\Thread\\ThreadSingleton();\n$singleton-\u003eexec('php scripts/script1.php');\n$singleton-\u003eexec('php scripts/script2.php');\n$singleton-\u003eanyRunning();\n$singleton-\u003estopAll();\n$singleton-\u003ereset\n```\n\nWorker and Singleton\n\n```php\n$worker = new Milanowicz\\Thread\\Worker([\n    'command' =\u003e '/bin/sleep 20',\n    'execMaxCounter' =\u003e 10, // How many would you execute?\n    'maxWorkers' =\u003e 2, // How process(es) should be started?\n], new Milanowicz\\Thread\\ThreadSingleton());\n$worker-\u003erun();\n```\n\n\n## Development\n\nRun all test suites\n```shell\n\u003e composer tests\n```\n\nRun PHP Code Styling\n```shell\n\u003e composer style\n```\n\nRun PHPStan to analyze code\n```shell\n\u003e composer analyze\n```\n\nRun PHPUnit tests\n```shell\n\u003e composer test\n```\n\nRun Mutation tests by Infection\n```shell\n\u003e composer infection\n```\n\n\n## License\n\n[GNU GPL Version 3](http://www.gnu.org/copyleft/gpl.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilanowicz%2Fphp-thread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilanowicz%2Fphp-thread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilanowicz%2Fphp-thread/lists"}