Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Realtime Echoing

    I've been running a php script on my shared hosting account, and this code typically runs for days as it indexes web pages. It constantly sends status info to the browser through 'echo'. Anyway, I got a dedicated server and after installing LAMP etc etc I ran the script and noticed that it doesn't show realtime information anymore - here's what i mean - take a look at this small script which echoes each second as it passes:
    PHP Code:
    <?php
    $counter 
    1;
    while (
    $counter 200) {
    sleep(1);
    echo 
    $counter."<br />";
    $counter++;
    }
    ?>
    When I run this on my shared hosting account, it actually displays each second as it passes in realtime, while on the dedicated it keeps 'loading' for 200 seconds and then suddenly displays all the numbers. What must be configured differently for this to happen? (I obviously want it to run in realtime) They're both running php 5, and I don't think its so much the type of hosting but something with php.ini, any ideas why this is happening? I can post both php.ini files if it helps.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,129
    Thanks
    2
    Thanked 328 Times in 320 Posts
    You need to disable all compression and buffering that php and your web server is doing. You can probably Google on how to do that for php and your specific web server.

    The whole Internet is not designed to work the way are you attempting. I seriously suggest if you want to update information on a web page this way that you use AJAX. While you might get it to work on your current servers, sooner or later you will end up on a server that you won't have the ability to change the necessary settings. This is also dependent on browser accept type settings, which would be out of your control for a visitor to your site other than yourself.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    amir103 (05-02-2009)

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You need to disable all compression and buffering that php and your web server is doing.
    Thanks I fixed it, I turned on implicit_flush to On in php.ini. I know what you mean though, I'm only using this script for server purposes it's not meant to be opened by visitors and it's practically impossible to convert it to use AJAX at this point. Thanks for your help I appreciate it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •