Breaking News
You are here : Home / Web development / PHP / Check Dead Links From Database Using PHP CURL
Checking Broken /dead links from database using PHP curl

Check Dead Links From Database Using PHP CURL

Check Dead/Broken Links From Database Using PHP CURL:

Hola Friends ! Checking Deadlinks From the database manually is a Headache ,So why not use a script which return the http status of the particular link and tell us if the link is dead or not.So how do we check the dead links from the database ? How do we programatically  check whether the link is dead or not ?

To check broken or dead links from Database we will use curl .Curl is PHP library which can make head HTTP head requests  which are good enough to find if a link is broken/dead or not.So why not we use CURL rather than fopen which uses more bandwidth.CURL saves our bandwidth and time.

So I have made a Script using PHP curl which check the deadlinks,which is Quite simple and easy.You can use this for checking single link or Use a for loop to iterate through the link from your database.So lets take a look at script which checks dead links from your database and iterate through each link and send a curl request to check whether link is invalid or not.


PHP Script To Check For Dead Links From Database:

Here is the Php function which check the dead links using could call it by supplying your url to this function and this function will return true if the link is online and false if link is dead.You can use this function to check the dead link .This can be used to check single link or multiple links.

That was easy ! now let me show you how to use this with multiple link from the database.

Check Invalid/Dead Links From Database :

Now we’ll use the same above function to check dead links from the database .We will iterate through the Links in our database . So we will connect to database collect all the links and iterate through all the links and if the link is dead then we store the link id in the array.that’w how we find all the dead links from the database.

That is how we Check all our dead links from the database using the curl library of the php.Also when this script run on server rather than desktop it will be much more faster.If you have 1000 or more link then it might give timeout error on localhost(xampp,wamp) , so to try it on the localhost use the limit ,then it will work fine.But on server it will work fine whether you have 1000 or 5000 links.

I hope You likes this Script ,Thanks for visiting on Design Aeon and keep visiting.


Tags : , , , , ,

4 Replies

  1. Pascal says:

    You should also use CURLOPT_FOLLOWLOCATION option, because of redirections. Your script will report 301 codes as invalid, but url can redirect to another page which is OK and returns 200 code.

  2. E says:

    Your checklink function features a number of typos… I doubt it ever works the way it is
    ($timeout is overiden, $url is replaced by undefined variable $link… )

    1. Ramandeep Singh says:

      Tnx Dude ,,I didn’t noticed that,,,

  3. norman says:

    Thanks for your great Social Media Plugin. Is there a way to include a facebook share button.

Leave a Reply

Want to join the discussion ? Feel Free to contribute !