This little script worked for me. I tested it with broken link on a server which redirects to a error page.
I put @fopen() instead of plain fopen() because it gives errors if it doesnt find what it is looking for.
<?php
$query="SELECT link FROM table";
$result=mysql_query($query);
while ($link=mysql_fetch_row($result))
{
$fd = @fopen($link[0],r);
if (!$fd) {
echo $link[0]." - Not working\n<br>";
}
else
fclose($fd);
}
?>