{"id":36843073,"url":"https://github.com/xuanwolei/scheduler","last_synced_at":"2026-01-12T14:30:29.181Z","repository":{"id":57086335,"uuid":"103206969","full_name":"xuanwolei/scheduler","owner":"xuanwolei","description":"php基于yiled实现的并行rpc调度器","archived":false,"fork":false,"pushed_at":"2019-12-26T07:43:04.000Z","size":17,"stargazers_count":16,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-16T19:23:53.605Z","etag":null,"topics":["php","php7","rpc","schedule","yield"],"latest_commit_sha":null,"homepage":null,"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/xuanwolei.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":"2017-09-12T01:33:24.000Z","updated_at":"2022-05-13T23:55:11.000Z","dependencies_parsed_at":"2022-08-25T00:50:33.350Z","dependency_job_id":null,"html_url":"https://github.com/xuanwolei/scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xuanwolei/scheduler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanwolei%2Fscheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanwolei%2Fscheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanwolei%2Fscheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanwolei%2Fscheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuanwolei","download_url":"https://codeload.github.com/xuanwolei/scheduler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuanwolei%2Fscheduler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28340398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["php","php7","rpc","schedule","yield"],"created_at":"2026-01-12T14:30:27.795Z","updated_at":"2026-01-12T14:30:29.140Z","avatar_url":"https://github.com/xuanwolei.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scheduler \nphp基于yiled实现的并行rpc调度器\n\n### 适用场景 ###\n\n同时请求多个api，而且响应时间比较长，并行化调用是个很好的方案。\n\n### 版本要求 ###\n\nphp \u003e= 5.6\n\ncurl扩展\n\n### composer安装 ### \n\n```shell\ncomposer require ybc429710096/scheduler dev-master\n```\n\n## 使用示例 ##\n\n### 并行化调用 ###\n\n```php\ninclude \"Scheduler/Autoload.php\";\nuse Scheduler\\Scheduler;\nuse Scheduler\\Curl;\n\n$time = microtime(true);\n\n$scheduler = new Scheduler;\n/**\n *\t第一个参数接受一个迭代生成器\n *  第二个参数接收一个回调函数，会把请求的内容返回\n */\n$scheduler-\u003enewTask(Curl::request(\"http://demo.xuanwolei.cn/sleep.php\"), function($data, Scheduler $scheduler){\n\t//输出请求返回内容\n\tvar_dump($data);\n});//3秒\n$scheduler-\u003enewTask(Curl::request(\"http://www.ali213.net/\"));//0.1秒\n$scheduler-\u003enewTask(Curl::request(\"http://www.ali213.net/\"));//0.1秒\n$scheduler-\u003enewTask(Curl::request(\"http://demo.xuanwolei.cn/sleep.php\"));//3秒\n$scheduler-\u003enewTask(Curl::request(\"http://demo.xuanwolei.cn/sleep.php\"));//3秒\n//运行\n$scheduler-\u003erun();\n\n//输出运行时间\necho \"run time:\".bcsub(microtime(true),$time,2); //3.1秒\n```\n上面的请求并行化调用耗时在3.1秒左右，下面我们看看串行化调用\n\n### 串行化调用 ###\n\n```php\ninclude \"Scheduler/Autoload.php\";\nuse Scheduler\\Scheduler;\nuse Scheduler\\Curl;\n\n$time = microtime(true);\n\n//平常的串行调用\n$curl = new Curl();\n$result = $curl-\u003ecallWebServer(\"http://demo.xuanwolei.cn/sleep.php\"); //3秒\nvar_dump($result);\n$curl-\u003ecallWebServer(\"http://www.ali213.net/\"); //0.1秒\n$curl-\u003ecallWebServer(\"http://www.ali213.net/\"); //0.1秒\n$curl-\u003ecallWebServer(\"http://demo.xuanwolei.cn/sleep.php\"); //3秒\n$curl-\u003ecallWebServer(\"http://demo.xuanwolei.cn/sleep.php\"); //3秒\n\n//输出运行时间\necho \"run time:\".bcsub(microtime(true),$time,2); //9.3秒\n```\n\n一共耗时9.3秒，可见对于响应时间较长的接口并行化调用带来的提升是巨大的\n\n### 并行化同时加入生成器 ###\n\n```php\ninclude \"Scheduler/Autoload.php\";\nuse Scheduler\\Scheduler;\nuse Scheduler\\Curl;\n\n$time = microtime(true);\n\n$scheduler = new Scheduler;\n/**\n *  第一个参数接受一个迭代生成器\n *  第二个参数接收一个回调函数，会把请求的内容返回\n */\n$scheduler-\u003enewTask(Curl::request(\"http://demo.xuanwolei.cn/sleep.php\"), function($data, Scheduler $scheduler){\n\t//输出请求返回内容\n\tvar_dump($data);\n});\n$scheduler-\u003enewTask(Curl::request(\"http://www.ali213.net/\"));\n$scheduler-\u003enewTask(Curl::request(\"http://www.ali213.net/\"));\n$scheduler-\u003enewTask(Curl::request(\"http://demo.xuanwolei.cn/sleep.php\"));\n//加入2个生成器\n$scheduler-\u003enewTask(generator());\n$scheduler-\u003enewTask(generator());\n//运行\n$scheduler-\u003erun();\n\n//输出运行时间\necho \"run time:\".bcsub(microtime(true), $time, 2); //3.4秒\n\n/**\n *\t生成器:执行完需要1秒\n */\nfunction generator(){\n\tfor ($i=0; $i \u003c 10; $i++) {\n\t\t//这里可以是业务逻辑，假设每次需要0.1秒\n\t\tusleep(100000);\n\t\tyield;\n\t}\n}\n```\n\n加入2个需要运行1秒的生成器后运行时间是3.4秒，比之前多了0.3秒，相当于节省了1.7秒时间。\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuanwolei%2Fscheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuanwolei%2Fscheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuanwolei%2Fscheduler/lists"}