<?php
ini_set( "display_errors" , "on" );
error_reporting(E_ALL);
ini_set( 'html_errors' , 'on' );
function fatal_error_handler($buffer) {
if (preg_match( "|(Fatal error</b>:)(.+)(<br)|" , $buffer, $regs) ) {
//
file_put_contents( "php://stderr" , "before fork (pid: " . getmypid() . ")\n" );
system( "php tester.php " . getmypid() . " &" );
return "ERROR CAUGHT, check log file" ;
}
return $buffer;
}
function handle_error ($errno, $errstr, $errfile, $errline)
{
if ($errno & E_ALL){
// -
//switch ,
switch ($errno) {
case E_USER_ERROR:
case E_USER_WARNING:
case E_USER_NOTICE:
default :
//do something
break ;
}
ob_end_clean();
echo "CAUGHT OTHER THAN FATAL ERRORS!!! " . $errstr;
exit;
}
}
//code between ob_start and ob_end_flush is included by MQ Handler, so we know nothing about it, and this code could fire a Fatal Error
if (isset($_SERVER[ "argv" ][1])){
file_put_contents( "php://stderr" , "kill {$_SERVER['argv'][1]}: " .var_export(posix_kill($_SERVER[ 'argv' ][1], 15), true ). "\n" );
}
ob_start( "fatal_error_handler" );
set_error_handler( "handle_error" );
while ( true ) {
//Just a Warning
//$a = 9/0;
sleep(10);
file_put_contents( "php://stderr" , "live\n" );
//Fatal error - -
if (rand(1,10) % 2 == 1) {
ololo(123);
}
}
/*
*/
$a = rand(1,10);
echo $a. "<br/>" ;
ob_end_flush();
echo "Program still executing...." ;
?>
* This source code was highlighted with Source Code Highlighter .
<?php
if (!checkSingleProcess()) {
exit;
}
function checkSingleProcess() {
$res = exec( 'ps aux | grep mq_manager.php | grep -v grep | grep -v ' .getmypid(), $output, $ return );
return $output == array();
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/73589/