GHz
27-04-2005, 18:02
Ciao a tutti,
mi servirebbero dei pareri su script per leggere il contenuto di una pagina web.
Io ho queste 2 funzioni:
function preleva ($url){
$handle = @fopen($url, "rb");
if (!$handle) {
return "";
}
$contenuto = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contenuto .= $data;
} while (true);
fclose($handle);
return $contenuto;
}
function getData($url) {
$numberOfSeconds=20;
$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
if($socketConnection) {
$xml = '';
fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
while(!feof($socketConnection)) {
$xml .= fgets($socketConnection, 128);
}
fclose($socketConnection);
}
return($xml);
}
Funzionano bene tutti e 2, l'unica cosa è che il secondo aggiunge della robaccia nella intestazione del tipo
HTTP/1.1 200 OK Date: Wed, 27 Apr 2005 16:00:00 GMT Server: Apache/1.3.33 (Unix) mod_fastcgi/2.4.0 PHP/4.3.10 X-Powered-By: PHP/4.3.10 Last-Modified: Wed, 27 Apr 2005 15:40:18 GMT Expires: Wed, 27 Apr 2005 17:40:18 GMT Cache-Control: public, max-age=7200 Connection: close Content-Type: text/html
e non so come toglierla....tocca farlo con strpos e substr....:mbe:
Quale delle due funzioni è più efficente nel caso di molte letture consecutive? Ce ne sono altre ancora meglio?
mi servirebbero dei pareri su script per leggere il contenuto di una pagina web.
Io ho queste 2 funzioni:
function preleva ($url){
$handle = @fopen($url, "rb");
if (!$handle) {
return "";
}
$contenuto = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contenuto .= $data;
} while (true);
fclose($handle);
return $contenuto;
}
function getData($url) {
$numberOfSeconds=20;
$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
if($socketConnection) {
$xml = '';
fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
while(!feof($socketConnection)) {
$xml .= fgets($socketConnection, 128);
}
fclose($socketConnection);
}
return($xml);
}
Funzionano bene tutti e 2, l'unica cosa è che il secondo aggiunge della robaccia nella intestazione del tipo
HTTP/1.1 200 OK Date: Wed, 27 Apr 2005 16:00:00 GMT Server: Apache/1.3.33 (Unix) mod_fastcgi/2.4.0 PHP/4.3.10 X-Powered-By: PHP/4.3.10 Last-Modified: Wed, 27 Apr 2005 15:40:18 GMT Expires: Wed, 27 Apr 2005 17:40:18 GMT Cache-Control: public, max-age=7200 Connection: close Content-Type: text/html
e non so come toglierla....tocca farlo con strpos e substr....:mbe:
Quale delle due funzioni è più efficente nel caso di molte letture consecutive? Ce ne sono altre ancora meglio?