2

我知道有很多关于已经发送输出的标头的线程,但是我对我的 Debian VM 有一个奇怪的影响(PHP 版本 5.3.3-7+squeeze15)

以下代码有效,尽管它不应该有效!

<?php
echo "test";
header("Location:http://www.example.com");
?>

有人知道它为什么起作用而且我没有收到“标头已发送警告”吗?

4

2 回答 2

7

php.ini设置的文件注释中output_buffering

; Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before pushing that
; data to the client. If your application's output exceeds this setting, PHP
; will send that data in chunks of roughly the size you specify.

; Turning on this setting and managing its maximum buffer size can yield some
; interesting side-effects depending on your application and web server.
; **You may be able to send headers and cookies after you've already sent output**
; through print or echo. You also may see performance benefits if your server is
; emitting less packets due to buffered output versus PHP streaming the output
; as it gets it. On production servers, 4096 bytes is a good setting for performance
; reasons.
于 2013-05-24T09:34:05.347 回答
2

尝试在回声后冲洗以使其不起作用

<?php
echo "test";
flush();
header("Location:http://www.example.com");
?>
于 2013-05-24T09:34:13.683 回答