Rich Darvins
Rich Darvins

Reputation: 371

Echo statements aren't being flushed properly?

I've been trying to debug this code for hours now, but haven't been making any headway. My print statements are simply not working. Another question suggested I flush(), but it's not working.

echo 'this never prints';
flush();
flush();
flush();

Any help would be appreciated.

Upvotes: 0

Views: 144

Answers (3)

Wrikken
Wrikken

Reputation: 70540

If you are inside an outbut buffer, which you can check with ob_get_level()>0, you can flush contents with ob_flush(). If you want to break out of all outbut buffers, this is a quick oneliner to end them all:

while(ob_get_level()>0) ob_end_flush();

Possibly use ob_end_clean() instead of ob_end_flush() if you want to discard the buffer(s).

Upvotes: 1

Garrett Smallwood
Garrett Smallwood

Reputation: 389

<?php
echo "Hello Web!";
?>

In this simple script you can see some of the most used components of a PHP script. First off, PHP tags are used to separate the actual PHP content from the rest of the file. You can inform the interpreter that you want it to execute your commands by adding a pair of these: standard tags ""; short tags ""; ASP tags "<% %>"; script tags " ". The standard and the script tags are guaranteed to work under any configuration, the other two need to be enabled in your "php.ini"

Upvotes: 0

erisco
erisco

Reputation: 14329

I think you have the display_errors directive off. Check your php.ini file to see if this is the case.

Your code has a syntax error; you are missing a semi-colon after the echo statement. Any syntax error can only be seen in the browser if display_errors is on.

php.net on display_errors: http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors

Upvotes: 3

Related Questions