Hi,
I'm trying to run an external perl script from another server in PHP 5.
I've tried using file_get_contents() but when I do, I get the following error:
Warning: file_get_contents($url): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
Then I went and got a hand-made PEAR version of file_get_contents:
function fgc($url) {
$url = str_replace("http://","",$url);
$url = str_replace("https://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
$socketConnection = fsockopen($domain, 80, $errno, $errstr);
if (!$socketConnection) {
echo "<!-- Network error: $errstr ($errno) -->";
}
else {
$xml = '';
fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
while (!feof($socketConnection)) {
$xml .= fgets($socketConnection, 128);
}
fclose ($socketConnection);
}
return($xml);
}
When I run fgc($url) to run the code above, I get this error:
HTTP/1.1 500 Internal Server Error Date: Tue, 07 Feb 2006 06:44:46 GMT Server: Apache/1.3.33 (Unix) Content-Length: 2044 Connection: close Content-Type: text/html
Does anyone have any idea how to make perl cgi scripts (residing on another server) run in PHP 5?
Take a look at fputs above, is that correct for a perl script?
Thanks