Re: fread over ftp

From: Date: Fri, 23 Feb 2001 22:58:01 +0000
Subject: Re: fread over ftp
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41400@lists.php.net to get a copy of this message
> if( !($fd = @fopen($ftp_url, "r")) ){ > $error = true; > $error_msg = "Unable to connect to server."; > } > else { > $file_contents = fread($fd, 100000); > 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), "<BR>\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

« previous php.general (#41400) next »