krlove / async-service-call-bundle
用于异步调用服务方法的Symfony组件
1.0.5
2017-12-10 15:40 UTC
Requires
- php: ^5.5 || ^7.0
- symfony/console: ^2.7 || ^3.0
- symfony/framework-bundle: ^2.7 || ^3.0
- symfony/monolog-bundle: ^2.7 || ^3.0
This package is auto-updated.
Last update: 2024-08-29 04:20:07 UTC
README
此组件允许您在后台进程中异步执行服务方法
安装
使用composer下载
composer require krlove/async-service-call-bundle
在AppKernel
中启用组件
$bundles = [
...
new Krlove\AsyncServiceCallBundle\KrloveAsyncServiceCallBundle(),
]
配置
选项
console_path
-console
脚本的路径。可以是绝对路径或相对于kernel.root_dir
参数值的相对路径。默认为Symfony 2.*的app/console
和Symfony 3.*的bin/console
。php_path
- php可执行文件的路径。如果配置中没有提供选项,则将使用Symfony\Component\Process\PhpExecutableFinder::find
来设置。
示例
# config.yml
krlove_async_service_call:
console_path: bin/console
php_path: /usr/local/bin/php
用法
定义任何服务
<?php
namespace AppBundle\Service;
class AwesomeService
{
public function doSomething($int, $string, $array)
{
// do something heavy
sleep(10)
}
}
注册服务
# services.yml
services:
app.service.awesome:
class: AppBundle\Service\AwesomeService
public: true
确保您的服务已配置为
public: true
异步执行doSomething
方法
$this->get('krlove.async')
->call('app.service.awesome', 'doSomething', [1, 'string', ['array']);
上面的代码将通过在异步执行krlove:service:call
命令来运行AppBundle\Service\AwesomeService::doSomething
方法。
如果成功,将返回进程PID,失败则返回null
。