Link to home
Create AccountLog in
Avatar of SJ TAN
SJ TAN

asked on

PHP curl time out error (28)

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;
        }
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
stale question
Avatar of SJ TAN
SJ TAN

ASKER

Hi, after many trials, I have found out the issue was due to the firewall of  Linux server I used did not open the port 8050.
After update it, the exact curl was functioning good.

Thanks a lot.