douxiegan6468 2012-03-29 11:00
浏览 16
已采纳

客户端标头信息

I have a web application build on PHP that (does some processing and) displays images hosted on external servers. Some of these images (i.e. from Flickr) when they are deleted, leave a redirect behind that points to a "Missing Image" gif or something equivalent.

By using the get_headers() function in php on each image, I was able to check server-side if an image was deleted or not (for example, by checking if the Content-Type was image/gif instead of image/jpg, on Flickr images).

The problem is that each page returns 20-100 images on average (sometimes even more), and get_headers() requires on average 0.3-0.5s for each image, thus making the wait time for the user too long.

I was wondering if this check could be done client-side, using javascript. The user will be waiting for the images to load (as with any page), I will be checking the images if they are valid, and set display property to none on the missing ones.

  • 写回答

3条回答 默认 最新

  • dsfds656545 2012-03-29 11:11
    关注

    You can use curl_multi_exec() to check multiple URLs at once. If you use the following cURL options:

    CURLOPT_FOLLOWLOCATION = FALSE
    CURLOPT_NOBODY = TRUE
    CURLOPT_HEADER = TRUE
    

    ...this will prevent the following of redirects. You can then use this information (whether the response is a redirect or not, see CURLINFO_HTTP_CODE in curl_get_info()) to determine whether the file exists. By using curl_multi_exec() you will perform multiple checks at once, which should drastically reduce the page load time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!