Results 1 to 4 of 4

Thread: Showing some result while waiting for socket connection

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Norway
    Posts
    88

    Showing some result while waiting for socket connection

    PHP Code:
    $host "www.yahoo.com";
    $fp fsockopen($host,80);

    //some http-connection stuff

    while (!feof($fp))
    echo 
    "getting site";
    $buf .= fgets($fp,128);
    fclose($fp);

    echo 
    $buf
    Problem with this is that it prints "getting site" a million times
    untill the socket is finished How can I make it print it only 1 time
    on the page? Also, how can I "clear" the page afterwards so just
    the result is shown?
    - zen

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    that is because you have it in a loop, take it out of that loop and put it before or after the while, my guess is that you need it before the loop. then when done just load a different page.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Norway
    Posts
    88
    Dont think you quite understood what I wanted to do But I kind
    of solved it. Just loaded a page with meta-refresh first. Doesn't
    do exactly what I wanted, but better than nothing
    - zen

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    umm yes I did, you say it was printing "getting site" a million times, well take it out of the loop and it will stop.

    while (!feof($fp))
    echo "getting site"; // inside the while loop
    $buf .= fgets($fp,128);
    fclose($fp);


    so then to print it once you do this

    echo "getting site";
    while (!feof($fp))
    $buf .= fgets($fp,128);
    fclose($fp);

    then it will only print that line and the results, no need to reload a page. hmmm sounds easy to me



Posting Permissions

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



Click Here to Expand Forum to Full Width