output-buffering

“headers already sent” Error returned during PHPUnit tests

安稳与你 提交于 2019-12-04 03:51:39
I'm testing a suite of REST web services with PHPUnit. We're using output buffering in order to gzip-encode the responses. When I run a test for the service with PHPUnit, I'm getting the error: Cannot modify header information - headers already sent by (output started at /home/dotcloud/php-env/share/php/PHPUnit/Util/Printer.php:172) It's complaining at the point that my code echo's the output to the browser... I was able to work around this temporarily by adding an ob_start() call at the top of the test class(es), but when I run multiple tests at once, I get this error again. Any ideas? Fabian

How to determine wether ob_start(); has been called already

*爱你&永不变心* 提交于 2019-12-04 01:53:47
I use output buffering for gzip compression and access to what was put out before in a PHP script: if(!ob_start("ob_gzhandler")) ob_start(); Now if that script gets included in another script where ob_start() already is in use I get a warning: Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in filename on line n So I'd like to test wether ob_start() has already been called. I think ob_get_status() should be what I need but what is the best way to use it in testing for this? ob_get_level returns the number of active output control handlers and ob_list

How to correctly show output at every echo on all browsers?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 15:08:07
I moved my files to a new server and I had a script that instantly showed output on every echo to the browser, but this isn't working on the new server. Here is my test code: @ini_set('output_buffering', 0); @ini_set('implicit_flush', 1); for ($i = 0; $i < ob_get_level(); $i++) ob_end_flush(); ob_implicit_flush(1); ignore_user_abort(true); set_time_limit(0); $max_wait_time = 30; $begin_time = microtime(true); $elapsed_time = 0; while(!connection_aborted()) { echo $i++.str_repeat(' ', 1020).'<br/>'; flush(); ob_flush(); usleep(1000000); if($elapsed_time > $max_wait_time){ break; } $elapsed_time

whats the difference between ob_flush and ob_end_flush?

怎甘沉沦 提交于 2019-12-03 13:08:44
i am confused about the PHP functions ob_flush() and ob_end_flush() . About the function ob_flush the manual says The buffer contents are discarded after ob_flush() is called.This function does not destroy the output buffer like ob_end_flush() does. i am confused about the words discarded and destroyed here . Even if the buffer contents are discarded in case of ob_flush() they cant be accessed and even if they are destroyed as in case of ob_end_flush() they cant be accessed. Then whats the difference between these two functions? UPDATE: In response to JamWaffles answer I dont understand the

Difference between ob_get_clean and ob_get_flush

孤者浪人 提交于 2019-12-03 05:30:31
问题 They both seem to do the same thing: return the output buffer content to you and delete it aftewards. Which one should I use? 回答1: To directly try to answer your question: If you wish to begin output buffering again after flushing the buffer, then use ob_get_clean as output buffering will still be ready without having turn it back on. (remember this can only be used if no text, even whitespace is echo'd to the browser). Thus for more general uses, all my programming books err towards ob_get

Difference between ob_get_clean and ob_get_flush

爱⌒轻易说出口 提交于 2019-12-02 18:48:27
They both seem to do the same thing: return the output buffer content to you and delete it aftewards. Which one should I use? To directly try to answer your question: If you wish to begin output buffering again after flushing the buffer, then use ob_get_clean as output buffering will still be ready without having turn it back on. (remember this can only be used if no text, even whitespace is echo'd to the browser). Thus for more general uses, all my programming books err towards ob_get_flush (as only one buffer per most scripts) ob_get_clean() removes the buffer (without printing it), and

How do I stop ZF from sending a empty character at the beginning?

倖福魔咒の 提交于 2019-12-02 06:33:07
问题 I'm developing an app using ZF which has a REST API. Everything is going well except that my XML has a blank character at the beginning and so the XML is breaking the rules of having the XML declaration at the beginning. I'm trying to consume this using javascript/jquery and I'm getting the following error on firebug's console: XML Parsing Error: XML or text declaration not at start of entity There are a number of posts on SO and other places on the web which discusses this. It is due to

How do I stop ZF from sending a empty character at the beginning?

我与影子孤独终老i 提交于 2019-12-02 03:40:41
I'm developing an app using ZF which has a REST API. Everything is going well except that my XML has a blank character at the beginning and so the XML is breaking the rules of having the XML declaration at the beginning. I'm trying to consume this using javascript/jquery and I'm getting the following error on firebug's console: XML Parsing Error: XML or text declaration not at start of entity There are a number of posts on SO and other places on the web which discusses this. It is due to output buffering and I've tried using ob_flush and flush as suggested elsewhere but I just can't figure out

Emacs/Python: running python-shell in line buffered vs. block buffered mode

核能气质少年 提交于 2019-12-01 18:29:07
In a related question and answer here , someone hypothesized that python-shell within emacs(23.2) was block-buffered instead of line-buffered. The recommended fix was to add sys.stdout.flush() to the spot in my script where I want stdio to flush its contents to the python-shell. Is there someway to trick python-shell (running in emacs 23.2 on Windows, not Linux) into either a) thinking it's attached to a TTY or b) using line-buffered instead of block-buffered mode? I don't see why I'd be able to do this in IDLE but not emacs. I'd rather customize emacs than add sys.stdout.flush() throughout my

Emacs/Python: running python-shell in line buffered vs. block buffered mode

你。 提交于 2019-12-01 17:15:13
问题 In a related question and answer here, someone hypothesized that python-shell within emacs(23.2) was block-buffered instead of line-buffered. The recommended fix was to add sys.stdout.flush() to the spot in my script where I want stdio to flush its contents to the python-shell. Is there someway to trick python-shell (running in emacs 23.2 on Windows, not Linux) into either a) thinking it's attached to a TTY or b) using line-buffered instead of block-buffered mode? I don't see why I'd be able