How to check for valid URLs?

Hi there,
      I am developing a site using PHP & MySQL. My DB contains thousands of URLs.

       For example:
            The URLs may be,

1, http://www.experts-exchange.com
2, http://www.experts-exchange.com/Web/Web_Languages/PHP
3, http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.jsp


      I am developing a page in that my client will click a button to get bad URLs i.e. the URLs that not open any page.

      For example:
            Bad URL
 http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.php

while the valid URL is

http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.jsp


How do I check bad URLs without using fopen? Because, it takes more time to check valid URLs and causes time out error.

Kindly Can any one help me to solve this problem?

Thanks in advance.
DubsJoyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThGCommented:
You may try with parse_url, and try to parse strings. But of corse you will find invalid urls, not non existent urls. What are you actually trying to do? Obviously, you can't distinguish between:
         Bad URL
 http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.php

while the valid URL is

http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.jsp

without opening a connection to the remote server..
0
lozlozCommented:
hi,

if you use this script, it won't time out and will tell you which urls are responding and which aren't.. you'll need to leave it running for a while i suppose but it'll give you a correct answer. you can modify it to update the database or remove dead entries if you want

<?
$query = "SELECT * FROM urls"; # change this query and the index of $row to match the column name
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
  set_time_limit(60);
  $url = @fopen($row["url"], "r");
  if($url) {
    print $row["url"] . " loads successfully<br />\n";
  } else {
    print $row["url"] . " failed to load..<br />\n";
  }
}
?>

tell me how you get on

loz
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DubsJoyAuthor Commented:
Hi ThG,
    yeah with out opening a connection to the remote server it is not possible.
i need faster checking for valid URLs.

For example:

code should say
http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.php 
is bad URL (becouse this page is not exist) and

http://www.experts-exchange.com/Web/Web_Languages/PHP/askQuestion.jsp
is valid URL
0
ThGCommented:
you have no faster ways than fopen(). Even if you write your own fsockopen(), request, and parse the output, you won't gain any appreciable speed..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.