Ok, penso di aver isolato il problema con wu-forecast.php e altervista.org
Usando questo per accedere a wunderground (che fa le previsioni meteo) sul mio sito altervista di prova
Codice PHP:
if(preg_match('|altervista.org|i',$_SERVER['SERVER_NAME'])) {
$Status .= "<!-- using file_get_contents() for altervista.org site -->\n";
$opts = array(
'http'=>array(
'method'=>"GET",
'protocol_version' => 1.1,
'timeout' => $numberOfSeconds,
'header'=>"Cookie: Units=metric;\r\n" .
"Cache-control: no-cache,max-age=0\r\n" .
"User-agent: PHP,WU-forecast.php,saratoga-weather.org\r\n" .
"Connection: close\r\n"
// "User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"
)
);
$context = stream_context_create($opts);
$Status .= "<!-- request context\n".print_r($opts,true)." -->\n";
$content = file_get_contents($url,false,$context);
$headers = implode("\r\n",$http_response_header);
$xml = $headers . "\r\n\r\n" . $content;
$Status .= "<!-- headers returned\n".$headers." -->\n";
Ottengo questo
Codice:
<!-- WU URL: http://www.wunderground.com/q/zmw:00000.39.WTERA -->
<!-- loading from http://www.wunderground.com/q/zmw:00000.39.WTERA. -->
<!-- using file_get_contents() for altervista.org site -->
<!-- request context
Array
(
[http] => Array
(
[method] => GET
[protocol_version] => 1.1
[timeout] => 10
[header] => Cookie: Units=metric;
Cache-control: no-cache,max-age=0
User-agent: PHP,WU-forecast.php,saratoga-weather.org
Connection: close
)
)
-->
<!-- headers returned
HTTP/1.0 200 OK
Cache-Control: no-cache, must-revalidate, no-cache="Set-Cookie", private
Date: Mon, 16 Jun 2014 22:13:26 GMT
Pragma: no-cache
Server: Apache/1.3.42 (Unix) PHP/5.3.2
Content-Type: text/html; charset=UTF-8
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Set-Cookie: ASC=1402956806:1; path=/; expires=Fri, 01-Jan-2020 00:00:00 GMT; domain=.wunderground.com
Set-Cookie: rc=%2C00000.WTERA; path=/; expires=Sat, 15-Jun-2019 22:13:27 GMT; domain=.wunderground.com
Set-Cookie: DT=1402956806:11169:365-o3; path=/; expires=Fri, 01-Jan-2020 00:00:00 GMT; domain=.wunderground.com
X-CreationTime: 0.367 -->
<!-- RC=200 OK, bytes=273185 -->
<!-- saved cache to ./WU-forecast-12-en.txt (273185 bytes) -->
<!-- using charsetInput='UTF-8' charsetOutput='ISO-8859-1' doIconv='1' doRTL='' -->
Usando invece lo stesso codice sul mio server XAMPP ho
Codice:
<!-- WU-forecast.php (ML) Version 2.06 - 16-Jun-2014 on PHP 5.4.4 -->
<!-- WU URL: http://www.wunderground.com/q/zmw:00000.39.WTERA -->
<!-- loading from http://www.wunderground.com/q/zmw:00000.39.WTERA. -->
<!-- using file_get_contents() for altervista.org site -->
<!-- request context
Array
(
[http] => Array
(
[method] => GET
[protocol_version] => 1.1
[timeout] => 10
[header] => Cookie: Units=metric;
Cache-control: no-cache,max-age=0
User-agent: PHP,WU-forecast.php,saratoga-weather.org
Connection: close
)
)
-->
<!-- headers returned
HTTP/1.1 200 OK
Date: Mon, 16 Jun 2014 22:25:43 GMT
Server: Apache/1.3.42 (Unix) PHP/5.3.2
Cache-control: no-cache, must-revalidate, no-cache="Set-Cookie", private
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
X-CreationTime: 1.318
Set-Cookie: ASC=1402957543:1; path=/; expires=Fri, 01-Jan-2020 00:00:00 GMT; domain=.wunderground.com
Set-Cookie: rc=%2C00000.WTERA; path=/; expires=Sat, 15-Jun-2019 22:25:45 GMT; domain=.wunderground.com
Set-Cookie: DT=1402957543:14342:365-g10; path=/; expires=Fri, 01-Jan-2020 00:00:00 GMT; domain=.wunderground.com
Connection: close
Content-Type: text/html; charset=UTF-8 -->
<!-- RC=200 OK, bytes=279887 -->
<!-- saved cache to ./WU-forecast-12-en.txt (279887 bytes) -->
<!-- using charsetInput='UTF-8' charsetOutput='ISO-8859-1' doIconv='1' doRTL='' -->
<!-- processing JSON entries for forecast -->
<!-- rawJSON size is 175798 bytes -->
<!-- Debug: saved JSON cache to ./WU-forecast-12-en-json.txt (175659 bytes) -->
<!-- json_decode returns - No errors -->
Che è la risposta "giusta" che anche altervista dovrebbe dare
Se lo cambio e forzo una richiesta http/1.0, ottengo lo stesso risultato che mi dà altervista
Nota che ho specificato HTTP/1.1 come protocollo, ma la risposta ritorna come HTTP/1.0 attraverso i server altervista.
Il quale è errato ... deve esserci qualche proxy server di altervista che sta modificando la richiesta e la sta forzando al formato HTTP/1.0 prima di darla a Wunderground per il processing, e che è ciò che deve essere fixato con altervista.
Mostra loro questo post e chiedigli di NON modificare le richieste HTTP/1.1 di default alle richieste HTTP/1.0 per file(),file_get_content() o processing con fconnect()/fread() per gli strams HTTP (trad.originale:Show them this post and ask them to NOT MODIFY HTTP/1.1 requests to default to HTTP/1.0 requests for file(),file_get_content() or processing with fconnect()/fread() for HTTP streams.)
Best regards,
Kim