0

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.

Rafael
  • 1,835
  • 3
  • 18
  • 26
Caio Maia
  • 61
  • 8
  • the problem might be the hosting server. – Junius L May 14 '17 at 13:59
  • Maybe but I think curl is a Very popular And usefull library that should not be blocked nor limited. Any suggestion for Free PHP hosts that fully support curl? – Caio Maia May 14 '17 at 14:11
  • the free accounts are on and off, they work, sometimes they don't – Junius L May 14 '17 at 14:13
  • Free hosts attract bad people looking to use it for spamming, scraping, attacks, etc. They'll typically be massively locked down. You get what you pay for. – ceejayoz May 14 '17 at 15:34
  • I'm voting to close this question as off-topic because it is likely an issue with the hosting provider rather than the code. – ceejayoz May 14 '17 at 15:34

1 Answers1

2

They block for outbound traffic. 000webhost said they blocked because of "too many phishing attacks".

Sources:

Community
  • 1
  • 1
Rafael
  • 1,835
  • 3
  • 18
  • 26
  • even this for paíd accounts? – Caio Maia May 14 '17 at 14:09
  • 1
    Probably not: "Due to abuse the services are being turn off. This is the trend of many free hosting service.". – Rafael May 14 '17 at 14:11
  • Any suggestion for Free PHP hosts that fully support curl? – Caio Maia May 14 '17 at 14:13
  • Amazon AWS give you 1 year free: https://aws.amazon.com/free/. You will have a server for you, but it is not as simple as 000webhost and hostinger. – Rafael May 14 '17 at 14:16
  • ,thank you for pointing me to the explanations about why curl is being blocked to avoid abuse but what about my code itself? is it OK ? regarding the logging is OK too ? Can I consider that the issue is only at the hosting provider? – Caio Maia May 14 '17 at 14:34
  • You are welcome :) I had no problem with your code (i tested it locally before searching any problem about the providers). Your logging is ok. But i think you should check also error.log file (this is from the provider). If you use AWS + Apache for your php, you should check your `/var/log/apache2/error.log` (the file will be different for others http servers, like nginx). – Rafael May 14 '17 at 15:02
  • Do You know If a paíd plan of that two hosters mentioned on this post Will allow for sure the use of curl ? If só, can You point me to where I can confirm that information? – Caio Maia May 14 '17 at 15:08
  • 1
    @CaioMaia ASK THE HOST. That said, AWS is a full VPS provider - as long as you install the cURL PHP extension (that's on you) you're good. – ceejayoz May 14 '17 at 15:35