output-buffering

How do headers work with output buffering in PHP?

五迷三道 提交于 2019-11-29 17:52:02
问题 Title is self-explanatory. I have a good bit of experience with PHP, but I am not sure how the header function works between ob_start() and ob_end_clean() . Consider this: ob_start(); echo "Some content"; header('X-Example-Header: foo'); echo "Some more content"; $output = ob_get_contents(); ob_end_clean(); echo $output; Does the header function ignore the output buffering, and thus all headers get sent before the content because it is echo ed after the header call? Or does it work some other

ob_get_level() starts at level 1

点点圈 提交于 2019-11-29 14:05:14
Having a few problems with output buffering. Mainly, I'm trying to run output buffering with the ob_gzhandler callback, but it keeps telling me its using an unsupported compression type. Everything is enabled, and I believe the problem is that running ob_get_level() at the start of my script produces a level of 1. php.ini has my output_buffering set to 4096. If I run something like: while(ob_get_level() > 0){ ob_end_clean(); } Then I can successfully run ob_start() with the ob_gzhandler callback. But I'm wondering if it should be a problem. During my script I make calls to ob_clean() at

PHP - htaccess - output_buffering

此生再无相见时 提交于 2019-11-29 10:52:25
I have the following code in an htaccess file in my application root to turn output buffering on. php_value output_buffering On php_value output_handler mb_output_handler On some servers it causes a 500 internal error, on others it works fine. Does anyone know why it sometimes causes an error. Is there a different way to do this? Thank you! You can use this syntax only if PHP is running as an Apache module. The 500 errors probably come up on servers where this is not the case. For total certainty, look into the server's error.log file for a detailed error message. Those directives work only if

PHP Output buffering, Content Encoding Error caused by ob_gzhandler?

天涯浪子 提交于 2019-11-29 10:11:51
Can anyone explain why I am receiving the following error? In the code, if the echo $gz; is commented out I receive no error (but also no output!), if it isn't I get (from Firefox), Content Encoding Error The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. Thanks for your help, here's the code: ob_start('ob_gzhandler') OR ob_start(); echo 'eh?'; $gz = ob_get_clean(); echo $gz; The output of your application should only contain one output encoding. If you have multiple chunks that are encoded differently, then the browser will get a

Is there a way to make PHP progressively output as the script executes?

倖福魔咒の 提交于 2019-11-29 07:47:38
So I'm writing a disposable script for my own personal single use and I want to be able see how the process is going. Basically I'm processing a couple of thousand media releases and sending them to our new CMS. So I don't hammer the CMS, I'm making the script sleep for a couple of seconds after every 5 requests. I would like - as the script is executing - to be able to see my echo s telling me the script is going to sleep or that the last transaction with the webservice was successful. Is this possible in PHP? Thanks for your help! Iain Use ob_flush to send any data in the buffer. So you can

PHP output buffering - sounds like a bad idea, is it?

南楼画角 提交于 2019-11-29 01:07:24
Just want to pick the experts' brains on php output buffering. There are times when I've wanted to implement it for one reason or another, but have always managed to rearrange my code to get around it. I avoid using it because it sounds like it'll cost resources. I mean, if they can offer the coder such wonderful flexibility, why don't they always buffer output? The only answer I can come up with is: because not buffering it saves tremendous resources, and with good coding practice you shouldn't need it. Am I way off here? From my experience, there isn't a significant impact on performance. I

Use case for output buffering as the correct solution to “headers already sent”

断了今生、忘了曾经 提交于 2019-11-28 13:35:40
I see (not just on this site) a lot of question from inexperienced PHP programmers about the infamous "headers already sent... output started at" error, and many people suggest using ouput buffering as a solution. In my experience I have never found a situation where that error wasn't caused by a flaw in the program's logic. Are there cases where output buffering is actually the correct solution? I would concur with your initial statement. Generally, solving "headers" problem with output buffering is a stopgap measure. The really sad/funny part of this solution is: what happens when you want

PHP - How Detect if Output Buffering is Turned On

*爱你&永不变心* 提交于 2019-11-28 12:13:55
Is there a simple way to detect in PHP if output_buffering is ON in php.ini? I'd like to be able to display a message if it is not turned on. Within my application I tried using an htaccess file to automatically turn it on but it seems it does not work in all server environments and in some cases it gives a nasty error. Thank you very much! You can check any INI setting in PHP with the ini_get method. http://php.net/ini_get ini_get('output_buffering'); Likewise, you can change most INI settings with ini_set : ini_set('output_buffering', 'on'); You can access the output_buffering value in the

Prevent output buffering with PHP and Apache

橙三吉。 提交于 2019-11-28 11:20:44
I have a PHP script which sends a large number of records, and I want to flush each record as soon as it is available: the client is able to process each record as it arrives, it does not need to wait for the entire response. I realize it takes slightly longer for the entire transfer because it needs to be sent in multiple packets, but it still allows the client to start working sooner. I've tried all the different flush() and ob_flush() functions but nothing seems to help get the data actually sent over the line before the page is finished. I've confirmed that it is not the web browser

ob_get_level() starts at level 1

我的未来我决定 提交于 2019-11-28 07:34:38
问题 Having a few problems with output buffering. Mainly, I'm trying to run output buffering with the ob_gzhandler callback, but it keeps telling me its using an unsupported compression type. Everything is enabled, and I believe the problem is that running ob_get_level() at the start of my script produces a level of 1. php.ini has my output_buffering set to 4096. If I run something like: while(ob_get_level() > 0){ ob_end_clean(); } Then I can successfully run ob_start() with the ob_gzhandler