https://github.com/normal-ai/thinkphp6-async-task
基于workerman的thinkphp6异步任务模型。
https://github.com/normal-ai/thinkphp6-async-task
async-task thinkphp thinkphp6 thinkphp6-async-task thinkphp6-workerman tp6-async-task workerman workerman-async-task
Last synced: about 1 month ago
JSON representation
基于workerman的thinkphp6异步任务模型。
- Host: GitHub
- URL: https://github.com/normal-ai/thinkphp6-async-task
- Owner: normal-ai
- Created: 2022-12-16T15:43:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T16:16:39.000Z (almost 2 years ago)
- Last Synced: 2024-08-10T11:58:15.687Z (over 1 year ago)
- Topics: async-task, thinkphp, thinkphp6, thinkphp6-async-task, thinkphp6-workerman, tp6-async-task, workerman, workerman-async-task
- Language: PHP
- Homepage:
- Size: 560 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# thinkphp6-async-task
## 介绍
基于workerman的thinkphp6异步任务模型
## 安装
~~~
composer require cathy/thinkphp6-async-task
~~~
## 使用
> 创建异步任务类及方法
~~~
update($i);
sleep(1);
}
$taskSynchronizer->done(['message'=>'Hi!'.$data['name']]);
}
}
~~~
> 执行异步任务
~~~
$asyncTaskProducer = new AsyncTaskProducer();
try {
$taskKey = $asyncTaskProducer->execute(
new AsyncTask(DemoAsyncTasks::class, 'demo', ['name'=>'cathy'])
);
echo $taskKey;
} catch (ExecAsyncTaskException|InvalidAsyncTaskException $e) {
echo $e->getMessage();
}
~~~
> 获取任务进度
~~~
try {
$taskKey = ''; // 执行异步任务得到的taskKey
echo json_encode(AsyncTaskAcquirer::get($taskKey));
} catch (Exception $e) {
echo $e->getMessage();
}
~~~