gpt4 book ai didi

php - 缺少 "headers already sent"- header 前的输出警告

转载 作者:行者123 更新时间:2023-12-02 06:36:43 27 4
gpt4 key购买 nike

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

下面的代码可以工作,但它不应该工作!

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

有谁知道为什么它可以工作并且我没有收到“ header 已发送警告”?

最佳答案

来自 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.

关于php - 缺少 "headers already sent"- header 前的输出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16731758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com