Reputation: 83
I have a lot of links in my database and lots of them are broken. Now I use this for cycle to get broken links:
$r = 0;
for($i=1;$i<10000;$i++){
$sqlt1 = mysqli_query($conn, "SELECT * FROM links WHERE id = '".$i."'");
while ($film = mysqli_fetch_array($sqlt1))
{
$id = $film['id'];
$link = $film['filmlink'];
$title = $film['filmtitle'];
$source = $film['source'];
}
$string = file_get_contents($link);
$array = array('not found', 'deleted', 'Has Been Removed', '%not be loaded%', '%create video code', 'Conversion stage:');
if($id == "")
{}
else{
if($string == "")
{
$result = "bad";
echo $id." <a href='$link' target='_balnk'>".$title."</a> ".$source." link ".$result."<br>";
mysqli_query($conn, "DELETE FROM links WHERE id = '".$id."'");
$r++;
}
elseif (strposa($string, $array, 1)) {
$result = "bad";
echo $id." <a href='$link' target='_balnk'>".$title."</a> ".$source." link ".$result."<br>";
mysqli_query($conn, "DELETE FROM links WHERE id = '".$id."'");
$r++;
}
else{
$result = "good";
}
}
}
echo "All bad links: ".$r;
But this way is very slow and usually I get timeout error. How can I analyse links faster?
Broken link sample: http://vidto.me/svib83bb3r7t.html
Upvotes: 1
Views: 44
Reputation: 598
The best will be asynchronous checks with using for example node.js
You'll have to write similar checks to this which you did in PHP, but in asynchronous way - you can connect node.js directly to your database
Or you can send every link status through for example PUT method to PHP server - but you'll have to setup the API endpoint for page.com/link/{id} and process it.
Upvotes: 1