output-buffering

PHP Output buffering, Content Encoding Error caused by ob_gzhandler?

元气小坏坏 提交于 2019-11-28 03:22:17
问题 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; 回答1: The output of your application should only contain

PHP buffer why \\r\\n

故事扮演 提交于 2019-11-28 02:05:20
I have a few conceptual questions (all related, I think) regarding the following script, at the comments. The script works fine. <?PHP ob_start(); // Create string to overflow browser buffer ...? $buffer = str_repeat(" ", 4096); // Indicate new header / html content ...? $buffer .= "\r\n<span></span>\r\n"; for ($i=0; $i<5; $i++) { echo $buffer.$i; ob_flush(); flush(); sleep(1); } ob_end_flush(); ?> First, why do I need to send the \r\n<tag>\r\n to the browser? I assume it has something to do with headers. Second, why do I need some HTML in the middle? Third, there are many examples that use

Calling ob_flush() and flush(), yet browser doesn't show any output until script finishes

﹥>﹥吖頭↗ 提交于 2019-11-28 01:48:08
Hi Please View Below Code : <?php ob_start(); echo "Start ...<br />\n"; for( $i = 0 ; $i < 10 ; $i++ ) { echo "$i<br />\n"; ob_flush(); flush(); sleep(1); } echo "End ...<br />\n"; ?> It's Incorrect ? i'm tested it but my output show when script is done, have any solution ? Hey man I was also got stuck in this problem and finally got the correct solution here it is for you you have to add content type for your page you can do that by two ways 1. using html tag <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> Ex. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

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

佐手、 提交于 2019-11-28 01:18:52
问题 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

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

泪湿孤枕 提交于 2019-11-27 21:33:15
问题 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

How to flush data to browser but continue executing

两盒软妹~` 提交于 2019-11-27 12:08:43
I have a ob_start() and a corresponding ob_flush() . I would like to flush a portion of data and continue executing the rest. Using ob_flush() didn't help. Also if possible rest needs to happen without showing loading in browser. EDIT: I don't want to use ajax Corbin ob_flush writes the buffer. In other words, ob_flush tells PHP to give Apache (or nginx/lighttpd/whatever) the output and then for PHP to forget about it. Once Apache has the output, it does whatever it wants with it. (In other words, after ob_flush it's out of your control whether or not it gets immediately written to the browser

Test PHP headers with PHPUnit

时光怂恿深爱的人放手 提交于 2019-11-27 10:54:30
I'm trying to use PHPunit to test a class that outputs some custom headers. The problem is that on my machine this: <?php class HeadersTest extends PHPUnit_Framework_TestCase { public function testHeaders() { ob_start(); header('Location: foo'); $headers_list = headers_list(); header_remove(); ob_clean(); $this->assertContains('Location: foo', $headers_list); } } or even this: <?php class HeadersTest extends PHPUnit_Framework_TestCase { public function testHeaders() { ob_start(); header('Location: foo'); header_remove(); ob_clean(); } } return this error: name@host [~/test]# phpunit --verbose

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

做~自己de王妃 提交于 2019-11-27 07:55:54
问题 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? 回答1: I would concur with your initial statement. Generally, solving "headers" problem with output

Prevent output buffering with PHP and Apache

假装没事ソ 提交于 2019-11-27 06:09:55
问题 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

PHP: Suppress output within a function?

会有一股神秘感。 提交于 2019-11-27 01:35:26
问题 What is the simplest way to suppress any output a function might produce? Say I have this: function testFunc() { echo 'Testing'; return true; } And I want to call testFunc() and get its return value without "Testing" showing up in the page. Assuming this would be in the context of other code that does output other things, is there a good method for doing this? Maybe messing with the output buffer? 回答1: Yes, messing with the Output Buffer is exactly the answer. Just turn it on before you call