Page 1 of 1
Website existance check
Posted: Thu Sep 28, 2006 4:21 am
by masondiamon
I have a database with a number of URLs. I want to check whether they exist or not using PHP script. I have tried ping each URL in the database using this code:
system ("-ping -c$count -w$count $url");
This works for most sites, but some even tho the website exist it wont ping it. Any other way I can do this?
Posted: Thu Sep 28, 2006 4:28 am
by volka
If you want to check "http-sites" you can send HEAD requests.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 wrote:The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself.
This method is often used for testing hypertext links for validity, accessibility, and recent modification.
e.g. with
pear's http_request class.
Code: Select all
<?php
require 'HTTP/Request.php';
$params = array(
'method'=>'HEAD',
'timeout'=>2.0,
'readTimeout'=>1.0
);
$req = new HTTP_Request('http://localhost/', $params);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
echo 'error:', $response->getMessage();
} else {
echo 'success:', $req->getResponseCode();
}
?>
Posted: Thu Sep 28, 2006 5:09 am
by masondiamon
Thanks for the reply. My pear folder is in another directory. So at the begining where it request "request.php" file I'll put in my directory? ie '../pear/request.php'.
Posted: Thu Sep 28, 2006 5:24 am
by volka
Maybe, but isn't the pear directory in php's include path?
see
http://www.php.net/manual/en/ini.core.p ... clude-path
Posted: Thu Sep 28, 2006 5:39 am
by masondiamon
when i do phpinfo() i get the following as the include_path .:/usr/share/pear . So do I just use that?
Posted: Thu Sep 28, 2006 6:10 am
by volka
Did you try?
Posted: Thu Sep 28, 2006 6:15 am
by masondiamon
Its ok, all I had to do was require 'Request.php'; and it goes to the pear directory. Thanks for your help.