Categorized | News

Simple Link Checker with PEAR

Posted on 30 August 2004 by Demian Turner

By slightly modifying one of the examples scripts from PEAR’s HTTP_Client package, you have yourself quite a useful link checker script.

Here’s the code:

To get things to work:

  • install the required classes using the PEAR package manager (if you’re not using this yet slap yourself on the wrist now):

    $ pear install HTTP_Request
    $ pear install HTPP_Client

    If you get an error about missing dependencies, obviously install the dependencies first.

  • change the $url variable to one of your sites you want to check (line 81)
  • load the script in a browser

The concept is simple:

  • Use HTTP_Request to return the html of a given webpage
  • use the extractlinks() function (slightly modified from Snoopy code) to get an array of links from the page
  • use HTTP_Client and a link checker listener (Observer pattern) to iterate through all the links and return the appropriate response code
  • colour code pass/fail responses and update the browser with flush()
Bookmark and Share

Leave a Reply



Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists



PHPkitchen recommends you also check out the following sites :

Accounting for Small Businesses

FreeAgent sign-up