Re: re:Timing out an fgets
| From: | Joseph H Blythe | Date: | Fri, 18 Aug 2000 06:01:06 +0000 |
| Subject: | Re: re:Timing out an fgets | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12413@lists.php.net to get a copy of this message | ||
jeremy brand wrote:
>
> 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...
>
>
Ok I tried the code it seems ok but made no difference to the result, as it will never hit the if
statment as fgets will just go forever (or until apache times out the request), the problem is fgets
isn't failing it is able to recieve the request just none is being sent so it just hangs, this
bings me right back to my original question how do I timeout an fgets?
If this isn't possible well maybe it should be, all file operations should maybe have an
optional timeout??
Im going completely bonkers on this one.
:-0
Joseph Blythe