Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flc1125/php-queue
PHP+redis队列
https://github.com/flc1125/php-queue
cli job-queue php queue redis
Last synced: 17 days ago
JSON representation
PHP+redis队列
- Host: GitHub
- URL: https://github.com/flc1125/php-queue
- Owner: flc1125
- License: mit
- Created: 2017-02-24T09:57:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-06T13:30:01.000Z (about 6 years ago)
- Last Synced: 2024-11-30T10:43:31.234Z (22 days ago)
- Topics: cli, job-queue, php, queue, redis
- Language: PHP
- Size: 11.7 KB
- Stars: 13
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php+redis消息队列
## 环境
- PHP >= 5.4
- composer## 安装
```
composer require flc/php-queue
```## 使用范例
producer
```php
/**
* 任务创建
*/
require_once __DIR__ . '/bootstrap.php';use Flc\Queue\Manager;
use Jobs\Demo;// 创建工作
$demo = new Demo('测试');// 推送到队列
for ($i = 0; $i <= 100; $i ++) {
Manager::instance()->push($demo);
}echo Manager::instance()->count();
```consumer
```php
/**
* 任务执行者(常驻)
*/
require_once __DIR__ . '/bootstrap.php';use Flc\Queue\Manager;
use Jobs\Demo;if ('cli' !== php_sapi_name()) {
die('必须在命令行模式下运行');
}while (true) {
// 从队列拉取任务
$job = Manager::instance()->pull();// 如无任务,则休息2秒
if (! $job) {
sleep(2);
continue;
}try {
call_user_func_array([$job, 'handle'], []);
} catch (Exception $e) {
echo $e->getMessage();
}
}
```## License
MIT