Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

ob_flush() not working

Discussion in 'General Discussion' started by Basil K Y, Jan 19, 2019.

  1. Basil K Y

    Basil K Y Registered

    Joined:
    Jan 19, 2019
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Kerala
    cPanel Access Level:
    Website Owner
    I'm using cpanel shared web hosting. I have tested my code on localhost and uploaded to server. Some of my php files takes around 5 minutes to complete execution (Some api call delays). I want to send response to the user early and I'm using ob_flush() for that. But the response is send only after complete execution.

    eg:

    <?php
    function closeConnection($body)
    {
    ob_end_clean();
    ob_start();
    echo $body;
    $size = ob_get_length();
    header("Connection: close\r\n");
    header("Content-Encoding: none\r\n");
    header("Content-Length: $size");
    ob_end_flush();
    @ob_flush();
    flush();
    }
    closeConnection('this should be shown');
    sleep(10);
    echo ' this should not be shown';


    In my local system, it shows "this should be shown" only and connection closes as expected. But from server, I gets "this should be shown this should not be shown" along with 10 seconds delay. I have spend hours without luck. This is holding me from publishing my website. Please help me to fix this.
     
  2. Basil K Y

    Basil K Y Registered

    Joined:
    Jan 19, 2019
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Kerala
    cPanel Access Level:
    Website Owner
    I have tested this code in an aws ec2 instance and it behaves as expected. Problem is only with shared hosting. Any help will be appreciated.
     
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,009
    Likes Received:
    2,123
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Basil K Y,

    A similar thread is linked below, but without root access you won't be able to make the suggested change or verify if those settings are applicable to your issue:

    Flush the output buffer in https / ssl, change the 64kb default

    I recommend reaching out to your web hosting provider for assistance. Your provider can verify how the system is configured (e.g. settings such as PHP handler, enabled Apache/PHP modules) and be able to better determine why ob_flush() isn't working as expected.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice