cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Weird cURL operation timed out error with HTTP POST

From: Phil <enterthesave-wix_at_yahoo.de>
Date: Tue, 19 Feb 2013 14:04:19 +0000 (GMT)

cURL-Version: 7.18.2
PHP Version: 5.3.17 (Suhosin Patch 0.9.10)

I'm getting a weird timeout when trying to use cURL to post to a server. The http_code of curl_getinfo() is 0.
"Operation timed out after 5000 milliseconds with 0 bytes received"

It does not depend on whether using HTTP or HTTPS.
The weird thing is: when omitting the content-length header, it works fine!
On another server with PHP 5.3.3-7 and cURL 7.21.0, everything works fine.

I attach these two files. Maybe anybody can confirm this issue?
Or does anybody have an idea what I'm doing wrong?
Thanks in advance. Phil

curltest_data.php
<?php
header('Content-type: application/json');
?>
{"ABC":"DEF"}
end curltest_data.php

curltest.php
<?php
$server = ''; // INSERT FULL URL OF curltest_data.php

$curlHandle = curl_init();

$str = json_encode(array());
$len = mb_strlen($str);
$headers = array('Content-type: application/json', 'Content-length: ' . $len); // WHEN OMITTING THIS CONTENT-LENGHT HEADER, IT WORKS FINE

curl_setopt($curlHandle,CURLOPT_HTTPGET,FALSE); 
curl_setopt($curlHandle,CURLOPT_POST,TRUE); 
curl_setopt($curlHandle,CURLOPT_POSTFIELDS, $str);
curl_setopt($curlHandle,CURLOPT_HEADER,TRUE);
curl_setopt($curlHandle,CURLOPT_NOBODY,FALSE);
curl_setopt($curlHandle,CURLOPT_TIMEOUT,5);
curl_setopt($curlHandle,CURLOPT_USERAGENT,'CURL');
curl_setopt($curlHandle,CURLOPT_URL,$server);
curl_setopt($curlHandle,CURLOPT_VERBOSE,TRUE);
curl_setopt($curlHandle,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curlHandle,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curlHandle,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curlHandle,CURLOPT_HTTPHEADER,$headers);

$responseContentsStr= curl_exec($curlHandle);
$responseContentsArr= explode("\r\n\r\n", $responseContentsStr);
echo 'DATA: ' . $str;
echo '<br />DATA LEN: ' . $len;
echo '<br />HEADERS: ';
print_r($headers);
echo '<br />ERROR: ' . curl_error($curlHandle);
echo '<br />';

$tmp = curl_getinfo($curlHandle);
print_r($tmp);
curl_close($curlHandle);

echo '<br />RESPONSE:<br />';

print_r($responseContentsArr);

phpinfo();
?>
end curltest.php

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2013-02-19