Website existance check

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
masondiamon
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 4:53 am

Website existance check

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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();
}
?>
masondiamon
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 4:53 am

Post 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'.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
masondiamon
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 4:53 am

Post by masondiamon »

when i do phpinfo() i get the following as the include_path .:/usr/share/pear . So do I just use that?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you try?
masondiamon
Forum Newbie
Posts: 5
Joined: Wed Sep 27, 2006 4:53 am

Post by masondiamon »

Its ok, all I had to do was require 'Request.php'; and it goes to the pear directory. Thanks for your help.
Post Reply