Problems using fsockopen, stream_set_timeout and fgets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fred H

    Problems using fsockopen, stream_set_timeout and fgets


    I'm communicating with a server using UDP, and it can be
    narrowed down to this:

    $us = 75000; //Timeout in microseconds.
    $con = fsockopen("udp://127.0.0.0","230 00");
    stream_set_time out($con,0,$us) ;
    fwrite($con"\xf f\info\");
    $retval = fgets($con,1024 0);

    My problem is that I allways have to wait for $us seconds.
    So if I set it to 2 seconds, I have to wait for 2 seconds.
    And if I set it to low, I might not wait long enough to get
    an answer. So I've ended up using 0.075 seconds, which isn't
    all that much. But I'd much rather find another way of
    doing this, so that I can set the timeout as high as I like,
    and still not have to wait longer than it takes to actually
    retrieve the data.

    Would reading one byte at a time, and check the last recieved
    bytes for a known pattern resolve this...? Any suggestions?

    -Fred

    P.S. I haven't been able to play around and try different things
    with this yet, due to deadlines on a couple of other projects...

    --
    Fred H

    void FredH::Contact( ) {
    TextToSpeach.sa y("frode at age dee dee dot en oh");
    }
  • Daniel C Bastos

    #2
    Re: Problems using fsockopen, stream_set_time out and fgets

    On Mon, 23 Feb 2004 14:58:01 +0000, Fred H wrote:
    [color=blue]
    > I'm communicating with a server using UDP, and it can be narrowed down to
    > this:
    >
    > $us = 75000; //Timeout in microseconds. $con =
    > fsockopen("udp://127.0.0.0","230 00"); stream_set_time out($con,0,$us) ;
    > fwrite($con"\xf f\info\");
    > $retval = fgets($con,1024 0);[/color]

    I don't see any reason to use stream_set_time out() with UDP since UDP is
    connectionless. Sometimes, fsockopen() won't even tell you that something
    went wrong; you'll find this out reading/writing to the resource.

    I say try working with it without the timeout. Look for errors using
    fwrite()/fgets() and then take the appropriate decisions.

    --
    Daniel

    Comment

    • Fred H

      #3
      Re: Problems using fsockopen, stream_set_time out and fgets

      > I don't see any reason to use stream_set_time out() with UDP since UDP is[color=blue]
      > connectionless. Sometimes, fsockopen() won't even tell you that something
      > went wrong; you'll find this out reading/writing to the resource.[/color]

      But if I read, and there is nothing to read, won't I just hang if I haven't
      set a timeout...?
      [color=blue]
      > I say try working with it without the timeout. Look for errors using
      > fwrite()/fgets() and then take the appropriate decisions.[/color]

      Doesn't work. It just hangs...



      --
      Fred H

      void FredH::Contact( ) {
      TextToSpeach.sa y("frode at age dee dee dot en oh");
      }

      Comment

      Working...