I have this code that works OK on my USBWebServerV8:
<?php
$url = "http://mobile.detran.ce.gov.br";
$curl_log = fopen('request.txt', 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Dalvik/1.6.0 (Linux; U; Android 4.4.2; Android SDK built for x86 Build/KK)");
curl_setopt($ch, CURLOPT_TIMEOUT, '5');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: mobile.detran.ce.gov.br'));
curl_setopt($ch, CURLINFO_HEADER_OUT, true); // enable tracking
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_STDERR ,$curl_log);
$page = curl_exec($ch);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );
print "<br/>".curl_error($ch)."<br/>";
print $headerSent."<br/>";
echo "<pre>". print_r($page, 1). "</pre>"."<br/>";
?>
But when I try to run the same code hosted (free plan) at www.000webhost.com and www.hostinger.com it gives me either a timeout ( 000webhost ) or a internal server error ( hostinger ).
Why would the same PHP code works locally but not at a free host?
Also, I tried to log but somehow my logging code above is not working as expected, it creates a file "request.txt" that is keeps blank after my requests.