fopensock not working.
Posted: Thu Mar 18, 2004 10:03 am
I have code that I developed a while ago, and inserted it into a site I am working on now. My development host is Red Hat Linux, Apache 1.3 server, MySQL server. This code works perfectly on it. My client has installed Apache 1.3 for Windows on his system and MySQL, and the site is up and running. However, this one method in the code does not work. Are there any options that need to be enabled for this to work? Is there something here that is not suppported in the Windows version of PHP? The symptoms are that it just plain freezes, like the fopensock is waiting to open the socket but never does.
Code: Select all
function loadImage($url) {
if ( !preg_match('/^(http:\/\/)?(ї\w\-\.]+)\:?(ї0-9]*)\/(.*)$/', $url, $url_ary) ) {
print_r(array_values($url_ary));
echo "Error - invalid image url - $filename";
}
$base_get = '/' . $url_aryї4];
$port = ( !empty($url_aryї3]) ) ? $url_aryї3] : 80;
if ( !($fsock = @fsockopen($url_aryї2], $port, $errno, $errstr)) )
{
echo "<br>Error<br>$errno<br>$errstr\n";
return false;
}
@fputs($fsock, "GET $base_get HTTP/1.1\r\n");
@fputs($fsock, "HOST: " . $url_aryї2] . "\r\n");
@fputs($fsock, "Connection: close\r\n\r\n");
unset($data);
while( !@feof($fsock) )
{
$data .= @fread($fsock,1024);
}
@fclose($fsock);
if (!preg_match('#Content-Length\: (ї0-9]+)ї^ /]ї\s]+#i', $data, $file_data1) || !preg_match('#Content-Type\: image/їx\-]*(їa-z]+)ї\s]+#i', $data, $file_data2))
{
echo "Error getting image<br>\n";
return false;
}
$filesize = $file_data1ї1];
$filetype = $file_data2ї1];
$data = substr($data, strlen($data) - $filesize, $filesize);
return $data;
}