fork download
  1. <?php
  2.  
  3. ini_set('display_errors', 1);
  4. header("Content-Type: text/plain; charset=utf-8");
  5.  
  6. $counter = 0;
  7.  
  8. // срабатывает при ошибке
  9. set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$counter) {
  10. echo "\n\n\nCounter=$counter\n";
  11. throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  12. });
  13.  
  14. for ($counter = 0; $counter < 10000; $counter++) {
  15. echo $counter % 10;
  16. setcookie('test', '12345', time() - 1);
  17. }
  18.  
  19. echo "END";
  20.  
Runtime error #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
0


Counter=0

Fatal error: Uncaught exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at /home/Rp2CmQ/prog.php:16)' in /home/Rp2CmQ/prog.php:17
Stack trace:
#0 [internal function]: {closure}(2, 'Cannot modify h...', '/home/Rp2CmQ/pr...', 17, Array)
#1 /home/Rp2CmQ/prog.php(17): setcookie('test', '12345', 975150411)
#2 {main}
  thrown in /home/Rp2CmQ/prog.php on line 17
stderr
PHP Fatal error:  Uncaught exception 'ErrorException' with message 'Cannot modify header information - headers already sent by (output started at /home/Rp2CmQ/prog.php:16)' in /home/Rp2CmQ/prog.php:17
Stack trace:
#0 [internal function]: {closure}(2, 'Cannot modify h...', '/home/Rp2CmQ/pr...', 17, Array)
#1 /home/Rp2CmQ/prog.php(17): setcookie('test', '12345', 975150411)
#2 {main}
  thrown in /home/Rp2CmQ/prog.php on line 17