Skip to content


Created: 2016-02-07 12:38:24 -0800 Modified: 2018-11-12 21:13:35 -0800


Solution: use curl.

$curl = curl_init('');
curl_setopt($curl, CURLOPT_PORT, 81);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 81);
$result = curl_exec($curl);

I had a problem with my light-control server when I’d switched web hosts. It turned out that the new host could only connect when I was using port 80 on my personal computer. I ended up just using port 80 instead of trying to get the server administrator to fix anything.

Helpful functions for debugging this:


ini_set(‘display_errors’, 1);

Also, there’s a site called that will tell you about a query that you send.

contents=filegetcontents( = file_get_contents('' . user . ‘&token=’ . token . '&cmd=' . cmd_number . ‘&light=’ . $light_number, false);

echo $contents;

Finally, apparently “allow_url_fopen” needs to be set in php.ini for this to work (although I think it was on in my case already).

Note: if you didn’t want to use file_get_contents for some reason, you could use curl (reference), but note that this won’t help if the server is blocking outgoing ports:

$curl = curl_init('');
curl_setopt($curl, CURLOPT_PORT, 7895);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 7895);
$result = curl_exec($curl);