我在PHP的內置服務器上出現錯誤輸出的奇怪問題,它看起來像一個錯誤,但我不是100%確定。PHP本地服務器 - 雙錯誤 - 錯誤與否?
示例腳本:
<?php
error_reporting(-1);
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('ignore_repeated_errors', true);
trigger_error('my notice', E_USER_NOTICE);
trigger_error('my warning', E_USER_WARNING);
如果您在控制檯(php example.php
),你會得到以下的,預期的產量執行此代碼:
PHP Notice: my notice in C:\php\example.php on line 7
PHP Stack trace:
PHP 1. {main}() C:\php\example.php:0
PHP 2. trigger_error('my notice', 1024) C:\php\example.php:7
PHP Warning: my warning in C:\php\example.php on line 8
PHP Stack trace:
PHP 1. {main}() C:\php\example.php:0
PHP 2. trigger_error('my warning', 512) C:\php\example.php:8
然而,如果你運行該腳本一個網頁(php -S localhost:9000 example.php
),然後打開URL,在控制檯中得到如下輸出:
PHP 7.1.10 Development Server started at Tue Oct 10 19:46:05 2017
Listening on http://localhost:9000
Document root is C:\php
Press Ctrl-C to quit.
[Tue Oct 10 19:46:06 2017] PHP Notice: my notice in C:\php\example.php on line 7
[Tue Oct 10 19:46:06 2017] PHP Stack trace:
[Tue Oct 10 19:46:06 2017] PHP 1. {main}() C:\php\example.php:0
[Tue Oct 10 19:46:06 2017] PHP 2. trigger_error('my notice', 1024) C:\php\example.php:7
[Tue Oct 10 19:46:06 2017] PHP Warning: my warning in C:\php\example.php on line 8
[Tue Oct 10 19:46:06 2017] PHP Stack trace:
[Tue Oct 10 19:46:06 2017] PHP 1. {main}() C:\php\example.php:0
[Tue Oct 10 19:46:06 2017] PHP 2. trigger_error('my warning', 512) C:\php\example.php:8
[Tue Oct 10 19:46:07 2017] PHP Notice: my notice in C:\php\example.php on line 7
[Tue Oct 10 19:46:07 2017] PHP Stack trace:
[Tue Oct 10 19:46:07 2017] PHP 1. {main}() C:\php\example.php:0
[Tue Oct 10 19:46:07 2017] PHP 2. trigger_error('my notice', 1024) C:\php\example.php:7
[Tue Oct 10 19:46:07 2017] PHP Warning: my warning in C:\php\example.php on line 8
[Tue Oct 10 19:46:07 2017] PHP Stack trace:
[Tue Oct 10 19:46:07 2017] PHP 1. {main}() C:\php\example.php:0
[Tue Oct 10 19:46:07 2017] PHP 2. trigger_error('my warning', 512) C:\php\example.php:8
最奇怪的是,如果在示例腳本的底部添加trigger_error('my error', E_USER_ERROR);
,則雙輸出是固定的。
這是什麼原因造成的? INI配置是一個錯誤還是一些怪異?
之前一切確保只有一個HTTP請求。您發佈的輸出對於兩個請求是正常的。 – axiac
你自己試過了嗎? – jurchiks
不知道如果這縮小了它,但我無法在我的Linux機器上覆制它。 –