We help IT Professionals succeed at work.
Get Started

PHP curl time out error (28)

SJ TAN
SJ TAN asked
on
1,058 Views
Last Modified: 2017-04-20
Hi,

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 = "http://smartacc.dyndns.org:8050/json";

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



SAMPLE PHP CODE:
$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')){
   curl_setopt($ch, CURLOPT_IPRESOLVE, 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;
        }
Comment
Watch Question
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE