Re: fgets() hang up?
| From: | Richard Lynch | Date: | Tue, 28 Nov 2000 22:56:12 +0000 |
| Subject: | Re: fgets() hang up? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27716@lists.php.net to get a copy of this message | ||
It's up to you to do some timing and data anticipation when working with
sockets.
If you get feof(), it's usually because the socket closed abnormally, I
think.
----- Original Message -----
From: Jon <apostolj@mail.lafayette.edu>
Newsgroups: php.general
Sent: Tuesday, November 28, 2000 10:29 AM
Subject: [PHP] fgets() hang up?
> When using a persistant connection, why does this code hang up on the
> fifth loop iteration (the socket connected to only returns four lines,
> so obviously its not quitting the loop when it should)
>
> // defined earlier on in the class:
>
> var $socket; // this is set and connected to when the object
> // is created (pfsockopen / fsockopen )
>
> function readAll()
> {
>
> $returnData = Array();
>
> while ( !feof( $this->socket ) )
> {
> echo ".";
> flush();
> $thisLine = fgets( $this->socket, 128 );
> if ( $thisLine != "" )
> $returnData[] = $thisLine;
> else break;
> }
>
> return $returnData;
> }
>
> // The socket is connecting, cause if I loop 4 times specifically, it
> // works fine.. it gets caught up on the fifth line..
> // the echo "." /flush() is simply for me to see where it's getting
> // caught
>
> Thanks! -- Jon
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>