{"id":17137368,"url":"https://github.com/baiy/think-async","last_synced_at":"2025-10-08T19:22:24.399Z","repository":{"id":62491360,"uuid":"294608748","full_name":"baiy/think-async","owner":"baiy","description":"thinkphp 异步代码执行/异步延迟执行/异步事件订阅","archived":false,"fork":false,"pushed_at":"2021-09-26T07:50:59.000Z","size":26,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-20T18:10:28.833Z","etag":null,"topics":["async","queue","subscribe","thinkphp"],"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/baiy.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":"2020-09-11T06:05:59.000Z","updated_at":"2025-08-05T08:56:16.000Z","dependencies_parsed_at":"2022-11-02T09:31:37.593Z","dependency_job_id":null,"html_url":"https://github.com/baiy/think-async","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/baiy/think-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baiy%2Fthink-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baiy%2Fthink-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baiy%2Fthink-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baiy%2Fthink-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baiy","download_url":"https://codeload.github.com/baiy/think-async/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baiy%2Fthink-async/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000701,"owners_count":26082805,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["async","queue","subscribe","thinkphp"],"created_at":"2024-10-14T20:06:53.556Z","updated_at":"2025-10-08T19:22:24.377Z","avatar_url":"https://github.com/baiy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# think-async for ThinkPHP 6\n\n* 提供 [ThinkPHP](https://github.com/top-think/think) 项目内部快速实现的`异步代码执行`/`异步延迟执行`/`异步事件订阅`功能\n* 内部由 [top-think/think-queue](https://github.com/top-think/think-queue) 提供异步队列支持\n* 执行流程: 调用相关方法将需要异步执行的代码插入相应队列中,使用`top-think/think-queue`提供的常驻监听脚本执行对应的代码,来实现系统的异步化\n\n## 安装\n\n```\ncomposer require baiy/think-async\n```\n\n## 配置\n\n```\nconfig/async.php\n```\n\n## 代码异步执行\n\n```php\nuse Baiy\\ThinkAsync\\Facade\\Async;\n// 异步执行代码\nAsync::exec($className,$methodName,...$params);\n// 异步执行代码使用自定义队列\nAsync::execUseCustomQueue($className,$methodName,$queue,...$params);\n// 异步延迟执行代码\nAsync::delay($delay,$className,$methodName,...$params);\n// 异步延迟执行代码使用自定义队列\nAsync::delayUseCustomQueue($delay,$className,$methodName,$queue,...$params);\n```\n### 例子\n```php\nnamespace app\\controller;\n\nuse Baiy\\ThinkAsync\\Facade\\Async;\nuse app\\BaseController;\nuse think\\facade\\Log;\n\nclass Index extends BaseController\n{\n    public function index()\n    {\n        // 异步执行\n        Async::exec(self::class, 'test', 'exec');\n        Async::execUseCustomQueue(self::class, 'test','async_exec_method_custom', 'exec');\n        // 异步延迟执行 延迟20秒\n        Async::delay(20, self::class, 'test', 'delay');\n        Async::delayUseCustomQueue(20, self::class, 'test','async_exec_method_custom', 'delay');\n        return '';\n    }\n\n    public static function test($type)\n    {\n        Log::info(\"异步执行的方法 {$type}\");\n    }\n}\n\n```\n\n## 事件订阅\n\n```php\nuse Baiy\\ThinkAsync\\Facade\\Async;\n// 事件触发\nAsync::trigger($name,...$params);\n```\n\n### 事件订阅配置\n\n默认使用`config/async.php`配置文件中`subscribe_event_config`进行配置,可使用`subscribe_event_get_class`来定制化配置来源\n\n## 内部日志拦截\n\u003e 可选操作, 不设置默认使用系统`\\think\\Log`方法进行日志记录\n\n```php\nuse Baiy\\ThinkAsync\\Facade\\Async;\nuse Psr\\Log\\LoggerInterface;\n/** @var LoggerInterface $log */\nAsync::setLog($log);\n```\n\n## 队列信息\n```php\nuse Baiy\\ThinkAsync\\Facade\\Async;\n// 获取所有队列标示\nAsync::queue();\n// 获取队列长度\nAsync::queueSize($queue);\n// 获取队列名称\nAsync::queueName($queue);\n```\n\n## 获取常驻脚本命令\n```\n## 执行下方命令会输出相关的队列监听命令\nphp think async:show\n\n## echo\n======= async_exec_method =======\nlisten mode:php think queue:listen --queue async_exec_method\nwork mode:php think queue:work --queue async_exec_method\n======= async_delay_method =======\nlisten mode:php think queue:listen --queue async_delay_method\nwork mode:php think queue:work --queue async_delay_method\n======= async_subscribe_demo =======\nlisten mode:php think queue:listen --queue async_subscribe_demo\nwork mode:php think queue:work --queue async_subscribe_demo\n```\n\u003e `listen`/`work`模式的区别和命令其他配置参数请查阅 [top-think/think-queue](https://github.com/top-think/think-queue) 文档\n\n## 其他说明\n1. 异步执行的方法均为静态公共方法(`public static`), 请知晓\n2. [top-think/think-queue](https://github.com/top-think/think-queue) 的默认配置是使用`同步模式`来消费队列, 请修改为异步模式","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaiy%2Fthink-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaiy%2Fthink-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaiy%2Fthink-async/lists"}