Re: re:Timing out an fgets

From: Date: Fri, 18 Aug 2000 05:39:10 +0000
Subject: Re: re:Timing out an fgets
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12411@lists.php.net to get a copy of this message
jeremy brand wrote: > > But you can use the predefined TRUE and FALSE values. > > So > > if (connection_timeout() == TRUE) > > But, I think they are defined to be: > TRUE 1 > FALSE 0 > > So, if for somereason, connection_timeout() returned 2, then > (connection_timeout() == TRUE) would not be true. > > it is correct to check like this: if (connection_timeout()) > > This is true throughout PHP. You have to just know what your function > returns. > > But, I don't think that connection_timeout() is what you want... you > just want fgets to fail. > > According to the php manual, fgets() returns a string on success and a > FALSE on failure. > > So, you should be able to do something like this: > > while (!feof($file_pointer)) > { > $string = fgets($file_pointer, 128); > if ($string == FALSE) > print "it didn't happen\n"; > else > { > /* do something with the string */ > $bigger_string .= $string; > } > } > > Question, if you can connect to the server anyway and get your valid file pointer, then what > protocol are you speaking... > > for example, if you get your file_pointer be using fsockopen() > then you had better send a request your self first to get something back.. > > on a web server, you would first have to > > $foo = "GET / HTTP/1.1\r\n\r\n"; > fwrite($file_pointer, $foo, strlen($foo)); > > Then, you should be able to receive data... > Otherwise, of course it is going to just hang... Thats correct my understanding is that what I have just written is a generic tcip interface, to cut a long story short I am writing a client interface to an Online Credit Card Verification server (OCV) so what I have sent it is just a standard ASCII string (a packet of information). Of course this string is very specific and has all sorts of requirements, this isn't my problem as the server is responding properly under normal circumstances. The OCV server then sends back an result, but in my case I am testing for an situation where a request has been sent, but for some unknown reason the server doesn't respond, it is upto me to recover from this condition, this is why I am trying to timeout the fgets as you said it will just hang, I thought the connection handling may be an easy way out but we will see.... Thanks for the clarification I will try the above example now... Regards, Joseph Blythe

« previous php.general (#12411) next »