【问题标题】:Fast check files exists in other server快速检查文件是否存在于其他服务器
【发布时间】:2013-10-30 01:37:43
【问题描述】:

我尝试检查是否存在于其他文件中,如果文件存在服务器响应 HTTP 200 如果不是 HTTP 302。 现在我尝试使用 get_headers() 函数进行检查,但它会变慢,因为文件大小约为 2mb-10mb,我会在一段时间内检查大约 20 个文件,它花费了大约 5-10 秒。 或许还有其他选择?

【问题讨论】:

    标签: php file exists


    【解决方案1】:

    尝试使用带有 CURLOPT_NOBODY 选项的 curl。

    例子:

    $ch = curl_init("http://www.other-server.com/file.jpg");
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    

    $response_code 将包含 HTTP 响应代码。

    【讨论】:

    • 现在好了~1 秒有 10 个文件。谢谢
    猜你喜欢
    • 2011-12-19
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2016-02-29
    相关资源
    最近更新 更多