MM_XSLTransform In my website I am getting some data from another site. I used a standard php script from Dreamweaver that works but if the other site is slow my page takes a long time to timeout and then finish loading.
After doing some research I believe it has to do with the code that uses fopen which does not have a built in timeout. I have been told I should use fsocketopen instead.
All of my attempts to change the code to use fsocketopen have failed. Can someone look at this function and let me know how to change it to use fsocketopen instead of fopen.
Thanks in advance for the help.
function getRemoteFile(&$src) {
$fileContent = '';
$pos = strpos($src, '://');
$protocol = strtolower(substr($src, 0, $pos));
// avoid protocol upper case
$mySrc = $protocol . substr($src, $pos);
$magic_quotes_runtime_orig = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
if ($myFile = @fopen($mySrc, 'rb')) {
while ($data = fread($myFile, 2048)) {
$fileContent .= $data;
}
fclose($myFile);
} else {
$this->setError($this->getErrorFromCode('MM_OPEN_REMOTE_ERROR', array($src)));
if ($protocol == 'https') {
$this->setError($this->getErrorFromCode('MM_HTTPS_OPEN_ERROR', array($src)));
if ( (substr(PHP_VERSION, 0, 1) < 5) && (substr(PHP_VERSION, 2, 1) < 3) ) {
$this->setError($this->getErrorFromCode('MM_HTTPS_NOT_SUPPORTED_ERROR', array($src)));
}
}
}
set_magic_quotes_runtime($magic_quotes_runtime_orig);
return $fileContent;
} |