PHP
Created: 2016-02-07 12:38:24 -0800 Modified: 2018-11-12 21:13:35 -0800
file_get_contents
Section titled file_get_contents1/30/2017
Solution: use 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:
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
Also, there’s a site called httpbin.org that will tell you about a query that you send.
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: