fopen versus sockets & timeouts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ggg@gg.com

    fopen versus sockets & timeouts

    Here's what I'm trying to do. The server serves up XML documents based
    on what I specify in the GET string. This is on a server I have no
    control over.

    There is a lag between the time when I issue the GET request, and when
    I actually get the response. (I suspect because the server has to dig
    for the data and format it. In any case, it's longer than say, a simple
    HTML page request to the web server.)

    When I manually cut and paste the GET url into a browser, it sometimes
    takes up to 20 seconds to get the response back (the popup tell me to
    save the file).

    When I fopen() it, sometimes it works, sometimes it doesn't. I tried
    using set_time_limit( 0), but that doesn't affect it.

    I believe I might have to do a socket call in order to have more fine
    tune control over the HTTP request.

    Am I heading down the right path?



  • Chung Leong

    #2
    Re: fopen versus sockets & timeouts

    <ggg@gg.com> wrote in message
    news:MPG.1c72d7 8394b04c8d98968 7@news.sf.sbcgl obal.net...[color=blue]
    > Here's what I'm trying to do. The server serves up XML documents based
    > on what I specify in the GET string. This is on a server I have no
    > control over.
    >
    > There is a lag between the time when I issue the GET request, and when
    > I actually get the response. (I suspect because the server has to dig
    > for the data and format it. In any case, it's longer than say, a simple
    > HTML page request to the web server.)
    >
    > When I manually cut and paste the GET url into a browser, it sometimes
    > takes up to 20 seconds to get the response back (the popup tell me to
    > save the file).
    >
    > When I fopen() it, sometimes it works, sometimes it doesn't. I tried
    > using set_time_limit( 0), but that doesn't affect it.
    >
    > I believe I might have to do a socket call in order to have more fine
    > tune control over the HTTP request.
    >
    > Am I heading down the right path?[/color]

    No. Check your stream timeout settings instead.


    Comment

    • ggg@gg.com

      #3
      streams &amp; file_get_conten ts()? can't set timeout?

      Hi,

      Thanks for the suggestion - I tried setting the socket timeout with
      stream_set_time out() and it seems to have fixed the problem:

      function get_fopen_conte nts($url)
      {
      if (!$handle = fopen("$url", "r")) return -1;
      stream_set_time out($handle, 1000);
      while (!feof($handle) )
      {
      $contents .= fread($handle, 8192);
      }

      if (fwrite($handle , $contents) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
      }
      fclose($handle) ;

      return $contents;
      }

      However, I didn't realize there already was a file_get_conten ts() so I'm
      using that.

      Now, I guess by using file_get_conten ts() I have no control over the
      timeout, because I need to refer to the handle of the stream in some
      way. Right?
      [color=blue]
      >
      > No. Check your stream timeout settings instead.
      >
      >
      >[/color]

      Comment

      Working...