PHP Curl with port number issue
This is a problem using PHP with Curl (on hosted server). I am trying to control a remote device (LED state) on port
54512 (for example). The
$url includes the
IP:port number concatenated with a short CGI command.
The following is a code fragment;
$sensorIP = "188.8.131.52:54512"; // IP:port format $url = $sensorIP . "/setParam.cgi?DOStatus_02=0" ; // set E2210 LED off echo $url; // $result = accessURL ($url); // set LED state on E2210 remote unit
This code times out. When I use the $url as an address in a web browser it works fine. So the receiving port 54512 is not blocked. When I use
IP:80 to form
$url it works fine (receiving port set to 80).I tried using the
CURLOPT_PORT option and the PHP script still times out.
The sending server outgoing HTTP is NOT blocking any port numbers, I checked with my hosting company. They believe I have a programming error, but where?
$sensorIP = "http://184.108.40.206:54512";
Make sure the outbound port 54512 is open (check with your hosting provider)
$output = curl_getinfo($ch);and print and check the output. you can get some info from that.
Dont include port number as part of url. Use the following instead:
curl_setopt($ch, CURLOPT_PORT, '54512');
I came across the same problem lately. I've tried almost everything, but no luck yet As far as I understood, curl does not work with other ports except 80. So the best solution here is to address curl on port 80 and you won't have any problems as I do now. Hope this info will help you.