[Phphtmllib-devel] SF.net SVN: phphtmllib:[3309] trunk/phphtmllib/src
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2009-12-01 05:44:43
|
Revision: 3309 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3309&view=rev Author: hemna Date: 2009-12-01 05:44:32 +0000 (Tue, 01 Dec 2009) Log Message: ----------- removed PEAR deps. Daemon children now use the Log class provided by phphtmllib Modified Paths: -------------- trunk/phphtmllib/src/mvc/Daemon.inc trunk/phphtmllib/src/mvc/ScheduleDaemon.inc trunk/phphtmllib/src/request/RequestBuilder.inc Modified: trunk/phphtmllib/src/mvc/Daemon.inc =================================================================== --- trunk/phphtmllib/src/mvc/Daemon.inc 2009-11-27 18:45:13 UTC (rev 3308) +++ trunk/phphtmllib/src/mvc/Daemon.inc 2009-12-01 05:44:32 UTC (rev 3309) @@ -84,6 +84,13 @@ const SIGTERM = 15; const SIGCHLD = 17; const SIGSTOP = 19; + + + /** + * Holds the Log object for + * logging messages. + */ + protected $log = null; /** * The constructor. @@ -99,6 +106,9 @@ //generate the PID filename //bassed off of the child class. $this->pid_file = $this->generate_pid_filename(); + + //initialize the logger + set_logger(get_logger()); //something to clean stuff up. register_shutdown_function(array(&$this, 'release_daemon')); @@ -116,18 +126,6 @@ /** - * Logs message - * - * @param string $message - * @param int $level (PEAR LOG level) - * @param Exception $exception - * @return void - */ - abstract protected function log_message($message, $level=PEAR_LOG_DEBUG, - $exception=NULL); - - - /** * This method is used to generate * the PID filename based off of the * name of the child class. @@ -152,6 +150,22 @@ * */ abstract protected function cleanup(); + + + /** + * This method is used to initialize the + * log class used. + */ + abstract protected function get_logger(); + + + /** + * set the logger used by this class + * + */ + protected final function set_logger(Log $log) { + $this->log = $log; + } /** @@ -160,7 +174,7 @@ * @return boolean */ public function start() { - $this->log_message('::start()'); + $this->log->debug('::start()'); //if it fails, we'll have an exception thrown. //caller needs to deal w/ it. @@ -176,8 +190,7 @@ $this->do_task(); $this->run_count++; } else { - $this->log_message("::reached max run count ".$this->run_count. ' '.$this->max_runs, - PEAR_LOG_INFO); + $this->log->info("::reached max run count ".$this->run_count. ' '.$this->max_runs); $this->disable(); } //lets touch the pid file to prove we @@ -188,7 +201,7 @@ //make sure we cleanly exit $this->cleanup(); - $this->log_message('::start() exiting.'); + $this->log->debug('::start() exiting.'); return true; } @@ -200,7 +213,7 @@ * @return void */ protected final function disable() { - $this->log_message('::disable()'); + $this->log->debug('::disable()'); $this->is_running = false; } @@ -216,7 +229,7 @@ * @return boolean */ public final function stop() { - $this->log_message('::stop() called'); + $this->log->debug('::stop() called'); $running_pid = @file_get_contents($this->pid_file); if (!$running_pid) { @@ -311,7 +324,7 @@ * Are we already running? */ public function is_daemon_running() { - $this->log_message('::is_daemon_running()'); + $this->log->debug('::is_daemon_running()'); $oldPid = @file_get_contents($this->pid_file); if ($oldPid !== false && posix_kill(trim($oldPid),0)) { @@ -329,16 +342,16 @@ * @return boolean. */ protected final function fork() { - $this->log_message('::fork()'); + $this->log->debug('::fork()'); $pid = pcntl_fork(); if ($pid == -1) { //oopsie. - $this->log_message('::fork() - Could not fork'); + $this->log->err('::fork() - Could not fork'); return false; } else if ($pid) { - $this->log_message('::fork() - calling exit()'); + $this->log->err('::fork() - calling exit()'); exit(); } else { //children? @@ -373,21 +386,21 @@ switch ($signal) { case self::SIGTERM: // Shutdown - $this->log_message(__CLASS__.'::SIGTERM signal'); + $this->log->info(__CLASS__.'::SIGTERM signal'); //let the loop know we must quit $this->disable(); break; case self::SIGSTOP: // Shutdown - $this->log_message(__CLASS__.'::SIGSTOP signal'); + $this->log->info(__CLASS__.'::SIGSTOP signal'); //let the loop know we must quit $this->disable(); break; case self::SIGCHLD: // Halt - $this->log_message(__CLASS__.' Child Halt signal'); + $this->log->info(__CLASS__.' Child Halt signal'); while (pcntl_waitpid(-1, $status, WNOHANG) > 0); break; } @@ -402,7 +415,7 @@ */ public final function release_daemon() { if ($this->is_child && file_exists($this->pid_file)) { - $this->log_message('::Releasing daemon'); + $this->log->debug('::Releasing daemon'); //nuke the PID file. unlink($this->pid_file); @@ -433,11 +446,11 @@ */ protected function touch_pid_file() { if (!file_exists($this->pid_file)) { - $this->log_message("::touch_pid_file() ".$this->pid_file." doesn't exist"); + $this->log->info("::touch_pid_file() ".$this->pid_file." doesn't exist"); } touch($this->pid_file, time()); - } + } } ?> \ No newline at end of file Modified: trunk/phphtmllib/src/mvc/ScheduleDaemon.inc =================================================================== --- trunk/phphtmllib/src/mvc/ScheduleDaemon.inc 2009-11-27 18:45:13 UTC (rev 3308) +++ trunk/phphtmllib/src/mvc/ScheduleDaemon.inc 2009-12-01 05:44:32 UTC (rev 3309) @@ -85,7 +85,7 @@ //first check local limits if ($this->can_run()) { //we can run - $this->log_message("::schedule()", PEAR_LOG_INFO); + $this->log->info("::schedule()"); //try and find a new item to work on. //and process it. @@ -102,8 +102,8 @@ public function start() { //make sure the suppression file doesn't exist if (file_exists($this->suppression_filename)) { - $this->log_message('::start() not starting because of suppression file '. - $this->suppression_filename, PEAR_LOG_INFO); + $this->log->info('::start() not starting because of suppression file '. + $this->suppression_filename); } else { //it's ok to start. parent::start(); @@ -119,10 +119,10 @@ */ public function test_daemon($script) { $pid_filename = $this->generate_pid_filename(); - $this->log_message("::test_daemon() ".$pid_filename, PEAR_LOG_INFO); + $this->log->info("::test_daemon() ".$pid_filename); if (file_exists($this->suppression_filename)) { - $this->log_message('::test_daemon() not starting because of suppression file '. + $this->log->debug('::test_daemon() not starting because of suppression file '. $this->suppression_filename); return; } @@ -133,8 +133,7 @@ try { $this->restart_daemon($script); } catch (Exception $e) { - $this->log_message("::test_daemon() ".$pid_filename." doesn't exist..restarted ".$script, - PEAR_LOG_WARNING); + $this->log->warning("::test_daemon() ".$pid_filename." doesn't exist..restarted ".$script); } return; } @@ -143,14 +142,14 @@ //ok file exists...make sure it's still alive. $cmd = "ps --no-heading -p ".$pid." -o cmd | grep ".$script; - $this->log_message("::test_daemon() running ".$cmd); + $this->log->debug("::test_daemon() running ".$cmd); $res = exec($cmd); if (strlen($res) <= 0) { try { $this->restart_daemon($script); } catch (Exception $e) { - $this->log_message(get_class($this)."::test_daemon() ".$pid_filename." wasn't running..restarted ".$script . " ".$e->getMessage(), - PEAR_LOG_WARNING); + $this->log->warning(get_class($this)."::test_daemon() ". + $pid_filename." wasn't running..restarted ".$script . " ".$e->getMessage()); } } } @@ -163,7 +162,7 @@ */ public function restart_daemon($script) { $cmd = "/usr/local/bin/php -f ".$script." </dev/null >/dev/null 2>&1"; - $this->log_message("::restart_daemon(".$script.") - ".$cmd); + $this->log->info("::restart_daemon(".$script.") - ".$cmd); $output = ''; $return = 0; exec($cmd, $output, $return); @@ -181,7 +180,7 @@ * Make sure you call enable_start() to clean up the file. */ public function disable_start() { - $this->log_message('::disable_start()', PEAR_LOG_INFO); + $this->log->info('::disable_start()'); if (!touch($this->suppression_filename)) { throw new DaemonException(get_class($this).'::disable_start() failed to create suppression file - '. $this->suppression_filename); @@ -194,7 +193,7 @@ * */ public function enable_start() { - $this->log_message('::enable_start()', PEAR_LOG_INFO); + $this->log->info('::enable_start()'); if (file_exists($this->suppression_filename)) { if (!unlink($this->suppression_filename)) { throw new DaemonException(get_class($this).'::disable_start() failed to create suppression file - '. @@ -210,8 +209,8 @@ * */ protected function wait_state() { - $this->log_message("::wait_state() for ".$this->wait_period." seconds", - PEAR_LOG_INFO); + $this->log->debug("::wait_state() for ".$this->wait_period." seconds"); + sleep($this->wait_period); } Modified: trunk/phphtmllib/src/request/RequestBuilder.inc =================================================================== --- trunk/phphtmllib/src/request/RequestBuilder.inc 2009-11-27 18:45:13 UTC (rev 3308) +++ trunk/phphtmllib/src/request/RequestBuilder.inc 2009-12-01 05:44:32 UTC (rev 3309) @@ -285,7 +285,7 @@ //this is an absolute request. $url = $this->get_protocol().$this->get_server().Request::SLASH.$this->get_file(); if (($query = $this->get_query_string()) && $query != '?') { - $url .= Request::SLASH.$this->get_query_string(); + $url .= $this->get_query_string(); } return $url; } else { @@ -294,7 +294,7 @@ if ($file) { $url = $file; if (($query = $this->get_query_string()) && $query != '?') { - $url .= Request::SLASH.$this->get_query_string(); + $url .= $this->get_query_string(); } return $url; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |