|
| 1 | +--TEST-- |
| 2 | +FPM: fatal error backtrace is reset before the next request's INI diagnostics |
| 3 | +--SKIPIF-- |
| 4 | +<?php include "skipif.inc"; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once "tester.inc"; |
| 9 | + |
| 10 | +$cfg = <<<EOT |
| 11 | +[global] |
| 12 | +error_log = {{FILE:LOG}} |
| 13 | +[unconfined] |
| 14 | +listen = {{ADDR}} |
| 15 | +pm = static |
| 16 | +pm.max_children = 1 |
| 17 | +env[ZEND_ASAN_FORCE_FAST_SHUTDOWN] = 1 |
| 18 | +EOT; |
| 19 | + |
| 20 | +$code = <<<'PHP' |
| 21 | +<?php |
| 22 | +echo getmypid(), "\n"; |
| 23 | +if (isset($_GET['fatal'])) { |
| 24 | + function trigger_fatal() { |
| 25 | + eval("class RequestReset {}; class RequestReset {}"); |
| 26 | + } |
| 27 | + trigger_fatal(); |
| 28 | +} |
| 29 | +echo date_default_timezone_get(), "\n"; |
| 30 | +PHP; |
| 31 | + |
| 32 | +$tester = new FPM\Tester($cfg, $code); |
| 33 | +$tester->start(iniEntries: [ |
| 34 | + 'fatal_error_backtraces' => '1', |
| 35 | + 'display_errors' => '0', |
| 36 | + 'log_errors' => '1', |
| 37 | + 'date.timezone' => 'UTC', |
| 38 | +]); |
| 39 | +$tester->expectLogStartNotices(); |
| 40 | +$response = $tester->request('fatal=1')->expectErrorPattern( |
| 41 | + '/\APHP message: PHP Fatal error: Cannot redeclare class RequestReset\b[^\n]*\n' |
| 42 | + . 'Stack trace:\n#0 [^\n]*: eval\(\)\n' |
| 43 | + . '#1 [^\n]*: trigger_fatal\(\)\n#2 \{main\}\z/' |
| 44 | +); |
| 45 | +$pid = $response->getBody(); |
| 46 | +var_dump(preg_match('/^\d+$/D', $pid) === 1); |
| 47 | + |
| 48 | +/* PHP_VALUE is applied before php_request_startup(), while shutdown is still flagged. */ |
| 49 | +$tester->request(headers: ['PHP_VALUE' => 'date.timezone=invalid']) |
| 50 | + ->expectBody($pid . "\nUTC") |
| 51 | + ->expectError("PHP message: PHP Warning: PHP Request Shutdown: " |
| 52 | + . "Invalid date.timezone value 'invalid', using 'UTC' instead in Unknown on line 0"); |
| 53 | +$tester->terminate(); |
| 54 | +$tester->expectLogTerminatingNotices(); |
| 55 | +$tester->close(); |
| 56 | + |
| 57 | +?> |
| 58 | +Done |
| 59 | +--EXPECT-- |
| 60 | +bool(true) |
| 61 | +Done |
| 62 | +--CLEAN-- |
| 63 | +<?php |
| 64 | +require_once "tester.inc"; |
| 65 | +FPM\Tester::clean(); |
| 66 | +?> |
0 commit comments