{"id":19083082,"url":"https://github.com/cr-mao/multi-process-worker","last_synced_at":"2025-02-22T06:21:59.802Z","repository":{"id":56958525,"uuid":"374389501","full_name":"cr-mao/multi-process-worker","owner":"cr-mao","description":"简单快速使用多进程处理任务","archived":false,"fork":false,"pushed_at":"2021-07-01T00:37:40.000Z","size":563,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-02T20:42:59.167Z","etag":null,"topics":["multi-process","pcntl","php-process","swoole","swoole-process"],"latest_commit_sha":null,"homepage":"","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/cr-mao.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}},"created_at":"2021-06-06T15:03:03.000Z","updated_at":"2023-08-23T07:58:12.000Z","dependencies_parsed_at":"2022-08-21T08:50:27.288Z","dependency_job_id":null,"html_url":"https://github.com/cr-mao/multi-process-worker","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cr-mao%2Fmulti-process-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cr-mao%2Fmulti-process-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cr-mao%2Fmulti-process-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cr-mao%2Fmulti-process-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cr-mao","download_url":"https://codeload.github.com/cr-mao/multi-process-worker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240133139,"owners_count":19752993,"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":["multi-process","pcntl","php-process","swoole","swoole-process"],"created_at":"2024-11-09T02:45:59.116Z","updated_at":"2025-02-22T06:21:59.221Z","avatar_url":"https://github.com/cr-mao.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e  muti process worker \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e use muti process worker do tasks  quickily and easily.\u003c/p\u003e\n\n## Introduction\n\nprovide child process work space ,you can do task in child work space in onWork function .\nalso it provide functions to get work content quickily and easily ,you can see `MultiProcessWorker::getWorkContentByIdMode` and  `MultiProcessWorker::getWorkContentByOffsetMode` \n\n\n\n## Requires\n\n - php \u003e 7.1.3\n \n - ext-pcntl enabled\n \n - ext-swoole optional\n  \n\n## Installing\n\n```shell\n$ composer require cr-mao/multi-process-worker\n```\n\n## Usage\n```php\n\nuse Crmao\\MultiProcessWorker\\MultiProcessWorker;\n\n$workNum = 4;\n$worker = new MultiProcessWorker($workNum, MultiProcessWorker::modePcntl);\n//$worker = new MultiProcessWorker($workNum, MultiProcessWorker::modeSwooleProcess);\n$worker-\u003eonWork = function ($workPage, $pid) use ($workNum) {\n    echo PHP_EOL;\n    echo \"工作空间编号:{$workPage},进程id:{$pid}\" . PHP_EOL;\n\n    //提供便捷函数，快速获得任务内容 ，模式一：id模式\n    list($beginId, $endId, $isLastWorkPage) = MultiProcessWorker::getWorkContentByIdMode($workPage, 4, 1, 100001);\n    //  select * from xxx where id \u003e={$beginId} AND id \u003c= {$endId},每个进程内可以自行在分页处理,  最后一个工作空间,你也许要考虑数据新增情况\n    echo \"begin mysql id is {$beginId}, end mysql id is {$endId}, 是否是最后一个工作空间:{$isLastWorkPage}\";\n    echo PHP_EOL;\n    \n    //提供便捷函数，快速获得内容 ，模式二: offset,limit 模式\n    list($offset, $limit, $isLastWorkPage) = MultiProcessWorker::getWorkContentByOffsetMode($workPage, $workNum, 10001);\n    echo \"offset is {$offset}, limit is {$limit}, 是否是最后一个工作空间:{$isLastWorkPage} \";\n    echo PHP_EOL;\n    sleep(3);\n};\n$worker-\u003estart();\n\n```\n\n\n## Contributing\ngithub.com:cr-mao/multi-process-worker\nYou can contribute in one of three ways:\n1. File bug reports using the [issue tracker](https://github.com/cr-mao/multi-process-worker/issues).\n2. Answer questions or fix bugs on the [issue tracker](https://github.com/cr-mao/multi-process-worker/issues).\n3. Contribute new features or update the wiki.\n\n_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._\n\n## License\n\nMIT\n\n## Links\n\n - https://www.php.net/manual/zh/book.pcntl.php\n\n - https://wiki.swoole.com/#/process/process?id=process\n \n - https://github.com/yidas/php-worker-dispatcher\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcr-mao%2Fmulti-process-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcr-mao%2Fmulti-process-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcr-mao%2Fmulti-process-worker/lists"}