Phanix
Phanix

Just writing

php buffering flush output & phalcon generate link in action

When the program needs to run for a long time, it will need to be used

If buffering flush is not used, it will wait for the program to finish executing before outputting. For the client side, it will feel like the browser has been trying to connect, which is not very good UX.

 public function execAction()
{
    ob_implicit_flush(1);
    ob_end_clean();
    set_time_limit(0);

    $url = new Url();
    for ($i = 0; $i < 10; $i++)
    {
        echo "hahaah<br>";
        ob_flush();
        flush();
        sleep(1);
    }
    ob_end_flush();
    flush();
    echo $this->tag->linkto("test/index", "Back to index");
}

Because the execution time may be very long, set the execution time limit, set_time_limit(0) . It should be noted that many files only mention that you need to call ob_start() before you can do buffering flush, but after testing it is found that you can do it without calling ob_implicit_flush(1) directly, and then calling ob_end_clean() to clear the buffer once. Then you can start using it.

In addition, the final $this->tag-&gtlinkto() phalcon function call can generate a link (using the default baseuri), and then echo it out (or display it in the desired position) and display it on the screen. In this way, the link can be dynamically generated.

Main reference https://stackoverflow.com/questions/4706525/php-flush-not-working

Original link: Phanix's Blog

CC BY-NC-ND 2.0

Like my work?
Don't forget to support or like, so I know you are with me..

Loading...

Comment