开发者

why echo does not show anything while php is busy

PHP Echo or Print functions does not show anything when php is busy with something (like when surfing the web with curl or something like that).

Later i discovered php do开发者_如何转开发es show the output when you execute your php on the command line:

php myscript.php

But right now i don't get any outputs from command line too! Is there any kind of tricks or setting should be done to make php show the outputs?


Chances are, it's caching the results (both in PHP and the web server) and not actually sending them to the browser yet. the best suggestion I can give is this chunk from my code:

/**
 * Act as a "breakpoint" in the code, forcing everything to be flushed to the browser
 */
function breakpoint() {
    global $debug;
    if ($debug) { // So that it doesn't slow down extracts
        ob_flush();
        flush();
        sleep(.1);
    }
}

The $debug stuff is if we're running the page in debug mode, specific to our website.

The two main thing you need are ob_flush(), which will send PHP's buffer to the web server's buffer, and flush() which will cause the server to dump to the browser. (Note: if the browser caches before displaying anything, nothing can prevent this) The sleep is there to help make sure it doesn't get overloaded, and has a chance to flush properly.

See: http://ca.php.net/manual/en/function.ob-flush.php and http://ca.php.net/manual/en/function.flush.php


Both PHP and your web server are likely to be caching the output of echo and print. This will often result in no output until the script completes.

Try looking at flush() to force the output out of PHP, but it still may get held up at the web server, so may not help...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜