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;
        }
LinuxPHP* Curl

Avatar of undefined
Last Comment
SJ TAN

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

stale question
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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy