Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meilleur gestion des erreurs #2

Merged
merged 2 commits into from Dec 1, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 26 additions & 7 deletions SystemDaemon.php
@@ -1,6 +1,16 @@
<?php
defined("PIDFILE_PREFIX") || define("PIDFILE_PREFIX", "/tmp");

if (!defined('E_RECOVERABLE_ERROR')) {
define('E_RECOVERABLE_ERROR', 4096);
}
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
if (!defined('E_USER_DEPRECATED')) {
define('E_USER_DEPRECATED', 16384);
}

require_once("pgq/SimpleLogger.php");
declare(ticks = 1);

Expand Down Expand Up @@ -72,6 +82,8 @@ abstract class SystemDaemon
protected $name;
protected $fullname;

protected $debug = false; // if true, stdin/out/err won't be closed

protected $pidfile;
protected $sid;
protected $killed = False;
Expand Down Expand Up @@ -198,13 +210,18 @@ public function start()
posix_strerror(posix_get_last_error()));
exit;
}
// don't forget a daemon gets to close those
fclose(STDIN); fclose(STDOUT); fclose(STDERR);

// reopen ids 0, 1 and 2 so that hard coded libs have no problem
fopen("/dev/null", "a+"); // STDIN
fopen("/dev/null", "a+"); // STDOUT
fopen("/dev/null", "a+"); // STDERR
if (!$this->debug) {
// don't forget a daemon gets to close those
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);

// reopen ids 0, 1 and 2 so that hard coded libs have no problem
fopen("/dev/null", "a+"); // STDIN
fopen("/dev/null", "a+"); // STDOUT
fopen("/dev/null", "a+"); // STDERR
}

/**
* config() provides log filename and loglevel
Expand Down Expand Up @@ -470,18 +487,20 @@ function phpFault( $errno, $errstr, $errfile, $errline )

case E_USER_ERROR:
case E_ERROR:
case E_RECOVERABLE_ERROR:
$this->log->error( $message );
$this->php_error_hook();
break;

case E_WARNING:
case E_USER_WARNING:
//case E_RECOVERABLE_ERROR:
$this->log->warning( $message );
return true;
break;

case E_STRICT:
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_NOTICE:
case E_USER_NOTICE:
$this->log->notice( $message );
Expand Down