Hi,
I'm trying to retrieve a file from a URL. This file is password protected with basic authentication, so I can't just use file() or something. I'll need to send some login headers, so I need to use a socket.
The problem is:
It doesn't receive anything.
Connecting to the server always succeeds, but the reading of the file (fgets) takes forever.
I varied all kinds of things. The current for() loop is my 5th attempt.
Am I forgetting something? Is there an easier way?
This is my code:
class adsl_status_update{
var $file_uri;
var $file_host;
var $username;
var $password;
var $STD_mysql_conn;
function adsl_status_update( $niet_doen = false ){
$this->file_uri = 'index.php';
$this->file_host = 'www.phpbuilder.com';
$this->username = '';
$this->password = '';
global $STD_mysql_conn;
$this->STD_mysql_conn =& $STD_mysql_conn;
if( !$niet_doen ){
$this->retrieve_file();
}
}
function retrieve_file(){
set_time_limit( 100 );
$fp = fsockopen($this->file_host, 80, $errno, $errstr, 1);
echo "connected!!!<hr>";
if( !$fp ){
echo $errno." ".$errstr;
}else{
// th plan was the following, but I'm trying to get a simpler version to work first.
//fputs ($fp, "GET /".$this->file_uri." HTTP/1.0\r\nHost: ".$this->file_host."\r\nAuthorization: Basic ".base64_encode( $this->username . ":" . $this->password )."\r\n");
fputs ($fp, "GET /".$this->file_uri." HTTP/1.0\r\nHost: ".$this->file_host."\r\n");
echo "question asked<hr>";
flush();
// exit();
// if I interrupt the script here, it echo's all yells above like it should.
for( $i = 0;$fiets = fgets ($fp,16) and $i < 100 and !feof($fp); $i++ ){
echo "$i: $fiets<br>";
flush();
}
fclose( $fp );
}
}
}