To update the IP addresses of various domains I use the DH APIs.
I have a PHP script that does that, and it has been working for at least a couple of years.
It uses CURL to contact https://api.dreamhost.com and retrieve the list of all domains and IPs I have setup.
If any IP changes, it updates DH.
Unfortunately sometimes last week it stopped working (I believe after an update to some ssl libraries on my side).
Here is the important part of the script (I removed some bits to keep it as short as possible):
[php]<?php //[..] //setup variables for script //[..] define('API_KEY', 'XXXXXXXXXXXXXXXX'); define('FORMAT', 'json'); define('PUBLIC_IP_SERVICE', 'http://myip.thewebisfree.com'); define('DREAMHOST_API', 'https://api.dreamhost.com'); $publicIp = file_get_contents(PUBLIC_IP_SERVICE); //[..] //check that "PUBLIC_IP_SERVICE" is up and/or $publicIp is a "valid IP" //[..] // Use your API url $apiCall = DREAMHOST_API.'/?key='.API_KEY.'&cmd=dns-list_records&format='.FORMAT; $command = 'curl'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiCall); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION, 3); //needed to force the SSL version after a php upgrade $data = curl_exec($ch); echo curl_error($ch); //decode JSON $data = json_decode($data); //[..] //with $data retrieved check that the IP hasn't changed, if it has update dreamhost... //[..] ?>
The errors I get are:
- Unknown SSL protocol error in connection to api.dreamhost.com:443 (printed by “echo curl_error($ch);”)
- PHP Notice: Trying to get property of non-object in scriptName.php on line 49 (which basically is “$data = json_decode($data);”)
If I enter “https://api.dreamhost.com/?key=XXXXXXXXXXXXXXXX&cmd=dns-list_records&format=json” in the browser I get the expected JSON list of domains;
How can I fix my curl commands to achieve the same result?
Any help/tip would be greatly appreciated.