【问题标题】:Is there a faster way to discover stored broken links?有没有更快的方法来发现存储的断开链接?
【发布时间】:2018-07-15 11:50:59
【问题描述】:

我的数据库中有很多链接,其中很多都已损坏。 现在我用这个循环来获取断开的链接:

$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;

但这种方式非常慢,通常我会收到超时错误。 如何更快地分析链接?

断开的链接示例:http://vidto.me/svib83bb3r7t.html

【问题讨论】:

    标签: php html for-loop


    【解决方案1】:

    最好的方法是异步检查,例如使用 node.js
    您必须编写与您在 PHP 中所做的类似的检查,但以异步方式 - 您可以将 node.js 直接连接到您的数据库

    或者您可以通过例如 PUT 方法将每个链接状态发送到 PHP 服务器 - 但您将 必须为 page.com/link/{id} 设置 API 端点并对其进行处理。

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 1970-01-01
      • 2011-12-20
      • 2018-12-12
      • 2016-02-06
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多