I have been using curl to get an xml response from a payment gateway since last january and before another one using the same code since about 5 years. Last friday it stopped working and the code hasn't been modified and both the host and the payment gateway tell me nothing has changed either.
I have done multiple tests to access the url with curl, fopen and file_get_contents to try to make it work. I seem to be able to access common sites like Google, Facebook and php.net but not the site I want and other sites i worked on.
The code I use for testing is :
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1); // comment once in production
if(!curl_setopt($ch, CURLOPT_URL, $url)) {echo 'CURLOPT URL Error<p>';}
if(!curl_setopt($ch, CURLOPT_HEADER, 1)) {echo 'CURLOPT Header Error<p>';}
if(!curl_setopt($ch, CURLOPT_HTTPHEADER, array('POST /AUTHORIZE HTTP/1.0', 'MIME-Version: 1.0', 'Content-type: application/PTI21',
'Content-transfer-encoding: text', 'Request-number: 1', 'Document-type: Request'))) {echo 'CURLOPT HTTPHEADER Error<p>';}
if(!curl_setopt($ch, CURLOPT_TIMEOUT, 90)) {echo 'CURLOPT TIMEOUT Error<p>';}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // gives error, but keeps xml formatting
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
$options = array(
'return_info' => true,
'method' => 'post'
);
$result = file_get_contents($url);
print_r($result);
$fd = fopen( $url, "r" );
if( !$fd )
{
echo "Cannot open URL";
} else {
while ( !feof( $fd ) ) {
$buffer = fgets( $fd, 4096 );
echo $buffer;
}
fclose ( $fd );
}
I was wondering if there was anything wrong with it because on another host it works everytime and with the host it's on, it only works for half the sites i try.