{"id":17035395,"url":"https://github.com/hhxsv5/php-coroutine","last_synced_at":"2025-04-12T12:51:08.685Z","repository":{"id":56984241,"uuid":"100013616","full_name":"hhxsv5/php-coroutine","owner":"hhxsv5","description":"A lightweight library to implement coroutine by yield \u0026 Generator.","archived":false,"fork":false,"pushed_at":"2017-08-17T08:54:56.000Z","size":12,"stargazers_count":27,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T07:36:14.646Z","etag":null,"topics":["coroutine","generator","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhxsv5.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":"2017-08-11T09:05:29.000Z","updated_at":"2024-07-09T09:50:13.000Z","dependencies_parsed_at":"2022-08-21T11:50:49.459Z","dependency_job_id":null,"html_url":"https://github.com/hhxsv5/php-coroutine","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/hhxsv5%2Fphp-coroutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhxsv5%2Fphp-coroutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhxsv5%2Fphp-coroutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhxsv5%2Fphp-coroutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhxsv5","download_url":"https://codeload.github.com/hhxsv5/php-coroutine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571346,"owners_count":21126516,"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":["coroutine","generator","yield"],"created_at":"2024-10-14T08:46:45.575Z","updated_at":"2025-04-12T12:51:08.660Z","avatar_url":"https://github.com/hhxsv5.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHP Coroutine\n======\n\nA lightweight library to implement coroutine by yield \u0026 Generator.\n\n## Requirements\n\n* PHP 5.5 or later\n\n## Installation via Composer([packagist](https://packagist.org/packages/hhxsv5/php-coroutine))\n\n```BASH\ncomposer require \"hhxsv5/php-coroutine:~1.0\" -vvv\n```\n\n## Usage\n### Run demo\n\n- PHP 5.5+\n\n```PHP\ninclude '../vendor/autoload.php';\n\nuse Hhxsv5\\Coroutine\\Scheduler;\n\n$start = microtime(true);\n/**\n * @param mixed \u0026 $return\n * @return Generator\n */\nfunction task1(\u0026$return)\n{\n    echo 'task1:start ', microtime(true), PHP_EOL;\n    $return = yield file_get_contents('http://www.weather.com.cn/data/cityinfo/101270101.html');\n    echo 'task1:end ', microtime(true), PHP_EOL;\n}\n\n/**\n * @param mixed \u0026 $return\n * @return Generator\n */\nfunction task2(\u0026$return)\n{\n    echo 'task2:start ', microtime(true), PHP_EOL;\n    $return = yield file_get_contents('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=yourtoken');\n    echo 'task2:end ', microtime(true), PHP_EOL;\n}\n\n$scheduler = new Scheduler();\n\n$t1 = task1($return1);\n$t2 = task2($return2);\n\n\n$scheduler-\u003ecreateTask($t1);\n$scheduler-\u003ecreateTask($t2);\n\n$scheduler-\u003erun();\n\nvar_dump($return1, $return2);\n\n$end = microtime(true) - $start;\necho $end;\n```\n\n- PHP7+ \n\n```PHP\ninclude '../vendor/autoload.php';\n\nuse Hhxsv5\\Coroutine\\Scheduler;\n\n$start = microtime(true);\n/**\n * @return Generator\n */\nfunction task1()\n{\n    echo 'task1:start ', microtime(true), PHP_EOL;\n    $ret = yield file_get_contents('http://www.weather.com.cn/data/cityinfo/101270101.html');\n    echo 'task1:end ', microtime(true), PHP_EOL;\n    return $ret;\n}\n\n/**\n * @return Generator\n */\nfunction task2()\n{\n    echo 'task2:start ', microtime(true), PHP_EOL;\n    $ret = yield file_get_contents('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=yourtoken');\n    echo 'task2:end ', microtime(true), PHP_EOL;\n    return $ret;\n}\n\n$scheduler = new Scheduler();\n\n$t1 = task1();\n$t2 = task2();\n\n$scheduler-\u003ecreateTask($t1);\n$scheduler-\u003ecreateTask($t2);\n\n$scheduler-\u003erun();\n\nvar_dump($t1-\u003egetReturn(), $t2-\u003egetReturn());//PHP 7+\n\n$end = microtime(true) - $start;\necho $end;\n```\n\n## License\n\n[MIT](https://github.com/hhxsv5/php-coroutine/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhxsv5%2Fphp-coroutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhxsv5%2Fphp-coroutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhxsv5%2Fphp-coroutine/lists"}