How can one check to see if a remote file exists using PHP?

前端 未结 22 2887
死守一世寂寞
死守一世寂寞 2020-11-22 05:52

The best I could find, an if fclose fopen type thing, makes the page load really slowly.

Basically what I\'m trying to do is

22条回答
  •  独厮守ぢ
    2020-11-22 06:26

    You should issue HEAD requests, not GET one, because you don't need the URI contents at all. As Pies said above, you should check for status code (in 200-299 ranges, and you may optionally follow 3xx redirects).

    The answers question contain a lot of code examples which may be helpful: PHP / Curl: HEAD Request takes a long time on some sites

提交回复
热议问题