- strpos: documentation ( source)
- str_repeat: documentation ( source)
- error_get_last: documentation ( source)
- memory_get_usage: documentation ( source)
- register_shutdown_function: documentation ( source)
- rand: documentation ( source)
<?php
//ini_set('memory_limit', '1M');
register_shutdown_function(function(){
echo "SHUTDOWN";
echo PHP_EOL;
$error = error_get_last();
if (isset($error)) {
if (0 === strpos($error['message'], 'Allowed memory size')) {
// ini_set('memory_limit', -1);
w('AFTER ERROR');
}
}
});
w('FIRST');
function w($a) {
echo $a;
echo PHP_EOL;
$r = 1000000;
while($r--) {
$m = str_repeat('a', 100000000);
echo memory_get_usage() . ":" . rand(1,4) ;
echo PHP_EOL;
}
}
echo "WORK FINE";