Re: [PHP] fread over ftp

2001-02-23 Thread Richard Lynch

> if( !($fd = @fopen($ftp_url, "r")) ){
>   $error = true;
>   $error_msg = "Unable to connect to server.";
> }
> else {
>   $file_contents = fread($fd, 10);
>   fclose($fd);
> }
>
> if( empty($file_contents) ){
>   $error = true;
>   $error_msg = "Did not read file.";
> }
>
>
> The problem is that the fread doesn't always succeed; about about half
> the time the $file_contents string tests as empty.  There is never a
> problem with the fopen, and there doesn't seem to be any consistancy in
> the failure...  The same file may be loaded into the string on run one,
> and missing the next.  The remote server is NT-based.
>
> Does anybody know what is going wrong here?  I don't have to add any logic
> to "wait" for the fread to complete, do I?

You do not need to "wait" for fread().  It blocks by default.  Unless you've
messed around with set_socket_blocking() somewhere else in your code?...

What *exactly* is the value of $file_contents when it fails?

echo "'$file_contents' ", gettype($file_contents), "\n";

If it is 0 or 'false' you can at least detect the problem and try again a
time or two...

--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] fread over ftp

2001-02-21 Thread Mark Heintz PHP Mailing Lists

I'm having some trouble reading a text file from a remote server into a
string.  The code is as follows:


if( !($fd = @fopen($ftp_url, "r")) ){
  $error = true;
  $error_msg = "Unable to connect to server.";
}
else {
  $file_contents = fread($fd, 10);
  fclose($fd);
}

if( empty($file_contents) ){
  $error = true;
  $error_msg = "Did not read file.";
}


The problem is that the fread doesn't always succeed; about about half
the time the $file_contents string tests as empty.  There is never a
problem with the fopen, and there doesn't seem to be any consistancy in
the failure...  The same file may be loaded into the string on run one,
and missing the next.  The remote server is NT-based.

Does anybody know what is going wrong here?  I don't have to add any logic
to "wait" for the fread to complete, do I?

Thanks,
mth.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]