Skip to content
Advertisement

file_get_html() not working in Google App Engine

I have some PHP code working perfectly in local and also in the web (with a non SSL hosting). I get file contents with file_get_html(url) and everything works OK.

The problem comes when I try to run this code in Google App Engine. The function file_get_html() doesn’t work.

The following code shows nothing between BEGIN and END:

<?php
header("Access-Control-Allow-Origin: *");

include './simple_html_dom.php';

$sitioweb = file_get_html("http://www.bolsamadrid.es/esp/aspx/Mercados/Precios.aspx?indice=ESI100000000");

echo "BEGIN<hr>";
echo $sitioweb;
echo "<hr>END";

Any help will be appreciated!

Advertisement

Answer

Finally I found the solution. I use curl instead file_get_html.

Code that doesn’t work for me in Google App Engine:

$sitioweb = file_get_html("http://www.bolsamadrid.es/esp/aspx/Mercados/Precios.aspx?indice=ESI100000000");

Code that work perfectly for me in Google App Engine:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.bolsamadrid.es/esp/aspx/Mercados/Precios.aspx?indice=ESI100000000');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($curl);
curl_close($curl);

$sitioweb = str_get_html($str);

It is a bit more verbose but works 🙂

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement