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?
Website existance check
Moderator: General Moderators
If you want to check "http-sites" you can send HEAD requests.
e.g. with pear's http_request class.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.
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();
}
?>-
masondiamon
- Forum Newbie
- Posts: 5
- Joined: Wed Sep 27, 2006 4:53 am
Maybe, but isn't the pear directory in php's include path?
see http://www.php.net/manual/en/ini.core.p ... clude-path
see http://www.php.net/manual/en/ini.core.p ... clude-path
-
masondiamon
- Forum Newbie
- Posts: 5
- Joined: Wed Sep 27, 2006 4:53 am
-
masondiamon
- Forum Newbie
- Posts: 5
- Joined: Wed Sep 27, 2006 4:53 am