Your code and approach is excellent. It seemed to me safe with most of the versions of PHP.
A thing regarding the curl. Its better to use this option for ssl
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false);
Otherwise you'll get the following error for the https protocol in some systems.
* SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
You can also try fsockopen()
to get the remote content. But for this one, you have to change the for number for different protocols.
$fp = fsockopen($domain, $portno, $errno, $errstr);