What is the fastest way to determine if a URL exists in PHP?

前端 未结 3 1592
借酒劲吻你
借酒劲吻你 2021-01-06 04:57

I need to create a function that returns if a URL is reachable or valid.

I am currently using something like the following to determine a valid url:

         


        
3条回答
  •  长情又很酷
    2021-01-06 05:44

    You'll likely be limited to sending some kind of HTTP request. Then you can check HTTP status codes.

    Be sure to send only a "HEAD" request, which doesn't pull back all the content. That ought to be sufficient and lightweight enough.

提交回复
热议问题