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:
JavaScript
x
<?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:
JavaScript
$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:
JavaScript
$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 🙂