codememe / codememedaemonbundle Goto Github PK
View Code? Open in Web Editor NEWRuns Symfony2 console commands as system daemon. Wrapper for System_Daemon PEAR library
Runs Symfony2 console commands as system daemon. Wrapper for System_Daemon PEAR library
In order to make all services configured easier and simplify dev. environments on non-pnctl compatible machines. Add DaemonicInterface for specifying start(), run(), restart() and stop() methods, configured for a daemon. Move config of daemons to service container tags.
The example command that is listed when running app/console
cannot be unlisted since it is part of the Bundle. This should be able to be removed from app/console
in some way. Maybe making it opt-in instead?
When you set the interval time to more than 2147 you will get an error: warning: [PHP Warning] usleep(): Number of microseconds must be greater than or equal to 0. As well daemon will not wait between iterations.
Similar problem is posted here:
http://pear.php.net/bugs/bug.php?id=19121
Solution is to use sleep() instead of usleep(). So the iterate method at Daemon class will looks like:
static public function iterate($sleepSeconds = 0)
{
self::_optionObjSetup();
if ($sleepSeconds >= 1) {
sleep($sleepSeconds);
} else if (is_numeric($sleepSeconds)) {
usleep($sleepSeconds * 1000000);
}
clearstatcache();
// Garbage Collection (PHP >= 5.3)
if (function_exists('gc_collect_cycles')) {
gc_collect_cycles();
}
return true;
}
The date format does not match the one used by Monologger. This makes it difficult to search or sort by date. Also makes it difficult to look at.
[Mar 15 13:56:07] info: master_builder System Daemon Started at 'March 15, 2012, 1:56 pm'
[2012-03-15 13:56:09] app.INFO: running... [] []
It should say [2012-03-15 13:46:07] info:
instead of [Mar 15 13:56:07] info:
. Also note that not having a year in the log will mean that they will overwrite each other annually.
The start
, stop
& restart
commands should be concrete within the bundle & simply allow for:
Large memory leaks are visible at short intervals iteration
<?php
protected function execute(InputInterface $input, OutputInterface $output)
{
$daemon = new Daemon($this->container->getParameter('example.daemon.options'));
$daemon->setInterval(0.001);
$daemon->start();
while ($daemon->isRunning()) {
//$this->container->get('example.control')->run();
}
$daemon->stop();
}
./app/console example:stop
top
(or another activity monitor) and see results;Occupied memory is growing at 500kb per minute at an interval of 100 ms
No leakage
Mac OS X
Darwin vatson-2.local 11.0.0 Darwin Kernel Version 11.0.0: Sat Jun 18 12:56:35 PDT 2011; root:xnu-1699.22.73~1/RELEASE_X86_64 x86_64
PHP
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
I found a reason. System_Daemon::setOptions
in the Daemon::isRunning
method causes memory leaks. I can not understand why we update the parameters at each iteration.
You may disregaurd this as it is an incompatibility with a Beta version of Symfony, however I wanted to list the issues I have run into:
1.) There is no composer.json in your package, and you are not listed in http://packagist.org/. Both of these actions should help you gain visability to your Bundle, and aid in your installation as composer is becoming the defacto standard.
2.) Even if you get around the composer.json issue in #1, "Class Symfony\Component\HttpKernel\Util\Filesystem does not exist" is thrown. I spent a few minutes attempting to rework the code for compatibility, but it fails.
Overall it looks like a bit of work will be needed to make this 2.1 compatible.
The example configuration under /Resources/config.yml
should instead be moved to Configuration.php
with actual defaults, including appPidLocation
:
https://github.com/CodeMeme/CodeMemeDaemonBundle/blob/master/Resources/config/config.yml
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.