file_get_contents timeout?

Do you realize there is a maximum number of characters that can be sent by the GET method after which the URI may be cropped. Try retrieving one of these long URIs in a browser to see how you get on.

URLs have a limit regardless. You want to post the variables to the ASP script instead, code from the documentation:


# $host includes host and path and filename
   # ex: "myserver.com/this/is/path/to/file.php"
# $query is the POST query data
   # ex: "a=thisstring&number=46&string=thatstring
# $others is any extra headers you want to send
   # ex: "Accept-Encoding: compress, gzip\\r\
"
function post($host,$query,$others=''){
   $path=explode('/',$host);
   $host=$path[0];
   unset($path[0]);
   $path='/'.(implode('/',$path));
   $post="POST $path HTTP/1.1\\r\
Host: $host\\r\
Content-type: application/x-www-form-urlencoded\\r\
${others}User-Agent: Mozilla 4.0\\r\
Content-length: ".strlen($query)."\\r\
Connection: close\\r\
\\r\
$query";
   $h=fsockopen($host,80);
   fwrite($h,$post);
   for($a=0,$r='';!$a;){
       $b=fread($h,8192);
       $r.=$b;
       $a=(($b=='')?1:0);
   }
   fclose($h);
   return $r;
}

If you use POST, you will be able to send more data to the ASP script.

Douglas

Not true!

The problem is many servers and clients don’t comply.

Not complying means they do not support it, thus there is some limit :slight_smile:

Remiya I think you are right. There server might not be handling the get method. I’ll try posting instead.

Just to be clear, this get file call


$xml = "<xml string here>";

$r = get_file_contents('http://server.com/path/script.aspx?SRC=$xml');

Is the equivalant to this post file call.


function post($host,$query,$others=''){
   $path=explode('/',$host);
   $host=$path[0];
   unset($path[0]);
   $path='/'.(implode('/',$path));
   $post="POST $path HTTP/1.1\\r\
Host: $host\\r\
Content-type: application/x-www-form-urlencoded\\r\
${others}User-Agent: Mozilla 4.0\\r\
Content-length: ".strlen($query)."\\r\
Connection: close\\r\
\\r\
$query";
   $h=fsockopen($host,80);
   fwrite($h,$post);
   for($a=0,$r='';!$a;){
       $b=fread($h,8192);
       $r.=$b;
       $a=(($b=='')?1:0);
   }
   fclose($h);
   return $r;
}

$xml = "SRC=<xml string here>";
$r = post('http://server.com/path/script.aspx', $xml,'')

Oh, what is the others variable for?

For extra headers looks like.

Douglas

Why do you pass the $xml variable to the asp script, what output do you expect as a result?
An XML content? Then why do you send XML in?

 $xml = "<xml string here>"; 
$r = get_file_contents('http://server.com/path/script.aspx?SRC=$xml');

Wouldn’t this be more understandable and error prone :slight_smile:

 $xml = "<xml string here>"; 
$r = get_file_contents('http://server.com/path/script.aspx?SRC='.$xml);

No particular reason, just an example. I guess I typed it too fast to make the distinction. Besides I don’t think it would change anything. I was more concerned about the equivalence between the two different methods.