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 port54512
(for example). The$url
includes theIP:port
number concatenated with a short CGI command.
The following is a code fragment;
$sensorIP = "77.134.85.187: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 useIP:80
to form$url
it works fine (receiving port set to 80).I tried using theCURLOPT_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?
Thanks! Al
Answer
Solution:
Workarounds:
Try
$sensorIP = "http://77.134.85.187:54512";
Make sure the outbound port 54512 is open (check with your hosting provider)
After
curl_exec()
function, add$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');
Answer
Solution:
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.