sadovnik/beanstalk-yii2
Composer 安装命令:
composer require sadovnik/beanstalk-yii2
包简介
Beanstalk component for Yii Framework 2
关键字:
README 文档
README
This is a temporary fork of https://github.com/sergebezborodov/beanstalk-yii2
#Beanstalk Worker App for Yii2
What is it?
Queries is important part for any big project. I used Gearman for years in my past projects and when I started develop hotwork.ru I read a lot of articles about different query system. Finnaly I chosed beanstalk - It was inspired by memcache protocol, it's simple, fast and stable. Beanstalk works at my server more than three month without restarting. For rabbitmq it will be unbelievable.
How to install
Install it by composer, add to composer.json
"sergebezborodov/beanstalk-yii2": "dev-master"
How to configure
For work with any query system you must create worker application. It must work permanently (at screen or supervisor) and listeting beastalk server. Client application set task to server and server call worker application for execution.
Create worker file, same as console:
#!/usr/bin/env php <?php $shared = require '...'; // load shared config of your app $worker = require '..../worker.php'; // worker app config $config = yii\helpers\ArrayHelper::merge($shared, $worker); $application = new sergebezborodov\beanstalk\Application($config); return $application->run();
Worker config example:
<?php /** * Config for beanstalk workers */ return [ 'on beforeAction' => function () { Yii::$app->db->open(); }, 'on afterAction' => function () { Yii::$app->db->close(); }, 'exitOnDbException' => true, // sometimes db gone away, it will be good to restart worker 'components' => [ 'router' => [ 'class' => 'sergebezborodov\beanstalk\Router', 'routes' => [ // routes list, example 'import' => 'import/worker/import', 'mail' => 'mail/worker/mail', ], ], ], ];
It's very important to close connection to database after worker completes task. Add all db connection to 'on beforeAction' and 'on afterAction' events.
##How to use
You must start worker with argument of tube name, for example:
./worker import - it will handle only tasks from import tube.
./worker - it will handle all tasks from all available tubes.
##Handling terminate signals
Terminate some tasks at execution will cause big problems, as solution app handle SIGINT signal (Ctrl+C) and wait for end of active task. You can disable with behavior by setting handleSignals property to false. PHP must be compiled with pcntl.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-21