uecode / daemon-bundle
Symfony2 守护进程包
Requires
- php: >=5.3.0
- ext-json: *
- uecode/daemon: ~1.0.2
- uecode/uecode-bundle: ~1.0.0
Requires (Dev)
- symfony/symfony: dev-master
Suggests
- monolog/monolog: Allows more advanced logging of the application flow
- react/react: Enables react support - use ReactCommand instead of ExtendCommand
This package is not auto-updated.
Last update: 2019-08-05 01:00:54 UTC
README
#Uecode DaemonBundle #
已弃用 / 停止支持
现在使用upstart或init.d将php命令守护化非常容易。请使用这些方法而不是此方法,因为您将获得更多支持。
##概述## DaemonBundle是Kevin Vanzonneveld创建的PEAR库System_Daemon的包装器。
这将使您能够安装symfony包,并轻松地将您的Symfony2控制台脚本转换为系统守护进程。
使用此功能需要配置PHP的二进制文件以使用pcntl。在我的Ubuntu服务器上,我能够使用以下命令轻松安装pcntl
sudo apt-get install php-5.3-pcntl-zend-server
##System_Daemon PEAR包## System_Daemon是一个PHP类,允许开发者在Linux系统上创建自己的守护程序应用程序。该类专注于创建 & 执行独立的守护进程
更多信息请见
##DaemonBundle配置##
此包需要Uecode\Bundle\UecodeBundle (https://github.com/uecode/uecode-bundle)
将Uecode\Bundle\Daemonbundle放在您的src目录中,并执行以下操作
composer.json
"uecode/daemon-bundle": "dev-master",
appKernel.php
将DaemonBundle添加到您的内核引导序列中
public function registerBundles()
{
$bundles = array(
//...
new Uecode\Bundle\DaemonBundle\DaemonBundle(),
);
//...
return $bundles;
}
config.yml
默认情况下,系统守护进程具有合理的配置。如果您需要更改任何配置设置,您可以通过将此配置添加到您的项目配置中来实现。只需添加需要更改的值,包扩展将合并您的守护进程配置到默认设置中。您必须至少拥有以下部分才能使用
app/config.yml
#Uecode DaemonBundle Config
uecode:
daemon:
config.yml - 额外
app/config.yml
#UecodeDaemonBundle Configuration Example
uecode:
daemon:
daemons:
#creates a daemon using default options
example: ~
#an example of all the available options
explicitexample:
appName: example
appDir: %kernel.root_dir%
appDescription: Example of how to configure the DaemonBundle
logDir: %kernel.logs_dir%
authorName: Aaron Scherer
authorEmail: aequasi@gmail.com
appPidDir: %kernel.cache_dir%/daemons/
sysMaxExecutionTime: 0
sysMaxInputTime: 0
sysMemoryLimit: 1024M
appUser: apache
appGroup: apache
appRunAsGID: 1000
appRunAsUID: 1000
##创建守护进程##
##代码## 确保您扩展\Uecode\Bundle\DaemonBundle\Command\ExtendCommand
<?php
namespace Uecode\Bundle\DaemonBundle\Command;
use \Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use \Symfony\Component\Console\Input\InputInterface;
use \Symfony\Component\Console\Input\ArrayInput;
use \Symfony\Component\Console\Output\OutputInterface;
use \Symfony\Component\DependencyInjection\Container;
use \Uecode\Bundle\DaemonBundle\System\Daemon\Exception;
use \Uecode\Bundle\DaemonBundle\Service\DaemonService;
/**
* Example Command class
*/
class ExampleCommand extends ExtendCommand
{
/**
* Configures the Command
*/
protected function configure()
{
$this
->setName( 'example' )
->setDescription( 'Starts an example Daemon' )
->setHelp( 'Usage: <info>php app/console example start|stop|restart</info>' )
->addArgument( 'method', InputArgument::REQUIRED, 'start|stop|restart' );
}
/**
* Sample Daemon Logic. Logs `Daemon is running!` every 5 seconds
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
protected function daemonLogic( InputInterface $input, OutputInterface $output )
{
// Do a little logging
$this->container->get( 'logger' )->info( 'Daemon is running!' );
// And then sleep for 5 seconds
$this->daemon->iterate( 5 );
}
}
##用法## 一旦您将symfony控制台命令守护化,您就可以像这样从命令行简单地运行它们
aequasi@ue:~/example$ php app/console queue:start
aequasi@ue:~/example$ php app/console queue:stop
aequasi@ue:~/example$ php app/console queue:restart