troubleshooting Question

PHP curl time out error (28)

Avatar of SJ TAN
SJ TAN asked on
LinuxPHP* Curl
4 Comments2 Solutions1059 ViewsLast Modified:

i have observe this error but still unable to find out why.

I use PHP cURL to post $d to URL $url.

 $d = array("version"=>1.1,"method"=>"postCashSale","params"=>"curltrial");
 $url = "";

we are expecting this response
{"version":"1.1","error":{"name":"JsonRPCError","code":"1","message":"Invoker method for postCashSale not found."}}

Here's the condition:
1. use HTML& JS HTTP and i am able to see response
2. use local win 10 XAMPP php script with CURL, i am able to see the response
3. putting script of (2) in linux cent os server at data center. now time get time out
   >> cURL Error #: (28) Connection timed out after 5000 milliseconds

$ch = curl_init();
$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $d);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);      
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp);
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
 $err = curl_error($ch);
 $errno = curl_errno($ch);
curl_close ($ch);

        if ($err) {
            return "cURL Error #: (".$errno.") " . $err;
        } else {
            return $response;
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros