Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Fixes #48 #50

Open
wants to merge 20 commits into
base: 2.1.1a
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Core/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ abstract class Core_Daemon
*/
private static $env = array(
'parent' => true,
'restart' => false
);


Expand Down Expand Up @@ -185,6 +186,7 @@ public static function getInstance()
try
{
$o = new static;
$o->getopt();
$o->setup_plugins();
$o->setup_workers();
$o->check_environment();
Expand Down Expand Up @@ -240,7 +242,6 @@ protected function __construct()
$this->set('filename', $argv[0]);
$this->set('start_time', time());
$this->pid(getmypid());
$this->getopt();
}

/**
Expand Down Expand Up @@ -337,9 +338,27 @@ public function __destruct()
{
$this->set('shutdown', true);
$this->dispatch(array(self::ON_SHUTDOWN));
foreach(array_merge($this->workers, $this->plugins) as $object) {
$this->{$object}->teardown();
unset($this->{$object});

foreach($this->workers as $key => $worker) {
if(!property_exists($this, $worker)) {
unset($this->workers[$key]);
continue;
}

$this->$worker->teardown();
unset($this->$worker);
unset($this->workers[$key]);
}

foreach($this->plugins as $key => $plugin) {
if(!property_exists($this, $plugin)) {
unset($this->plugins[$key]);
continue;
}

$this->$plugin->teardown();
unset($this->$plugin);
unset($this->plugins[$key]);
}
}
catch (Exception $e)
Expand Down Expand Up @@ -890,7 +909,9 @@ private function auto_restart()
if (!$this->is('parent') || !$this->is('daemonized'))
return;

if ($this->runtime() < $this->auto_restart_interval || $this->auto_restart_interval < self::MIN_RESTART_SECONDS)
if (($this->runtime() < $this->auto_restart_interval ||
$this->auto_restart_interval < self::MIN_RESTART_SECONDS) &&
!$this->get('restart'))
return false;

$this->restart();
Expand All @@ -906,6 +927,8 @@ public function restart()
if (!$this->is('parent') || !$this->is('daemonized'))
return;

// recover workers when restarting
$this->set('recover_workers', true);
$this->set('shutdown', true);
$this->log('Restart Happening Now...');

Expand All @@ -918,7 +941,7 @@ public function restart()
if (is_resource(STDOUT)) fclose(STDOUT);
if (is_resource(STDERR)) fclose(STDERR);
if (is_resource(STDIN)) fclose(STDIN);
exec($this->command());
exec($this->command() . ' --recover_workers');

// A new daemon process has been created. This one will stick around just long enough to clean up the worker processes.
exit();
Expand Down Expand Up @@ -1000,7 +1023,7 @@ protected function plugin($alias, Core_IPlugin $instance = null)
*
* @param String $alias The name of the worker -- Will be instantiated at $this->{$alias}
* @param callable|Core_IWorker $worker An object of type Core_Worker OR a callable (function, callback, closure)
* @param Core_IWorkerVia $via A Core_IWorkerVia object that defines the medium for IPC (In theory could be any message queue, redis, memcache, etc)
* @param Core_IWorkerVia $via A Core_IWorkerVia object that defines the medium for IPC (In theory could be any message queue, redis, memcached, etc)
* @return Core_Worker_ObjectMediator Returns a Core_Worker class that can be used to interact with the Worker
* @todo Use 'callable' type hinting if/when we move to a php 5.4 requirement.
*/
Expand Down
5 changes: 5 additions & 0 deletions Core/IWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*
* You can use the Core_Daemon::on(ON_FORK) method to provide universal setup code that is run after every fork and
* in every worker. The setup() method defined here can be used if you want specific setup code run in this forked process.
*
* @method boolean is_idle() Does the worker have at least one idle process?
* @method integer status(integer $call_id) Determine the status of a given call. Call ID's are returned when a job is called.
* @method number running_count() Retrieves the number of worker processes that are currently running
*
*/

interface Core_IWorker
Expand Down
181 changes: 0 additions & 181 deletions Core/Lib/Memcache.php

This file was deleted.

Loading