What is the easiest way to use the HEAD command of HTTP in PHP?

前端 未结 5 653
轻奢々
轻奢々 2020-12-03 11:31

I would like to send the HEAD command of the Hypertext Transfer Protocol to a server in PHP to retrieve the header, but not the content or a URL. How do I do this in an effi

5条回答
  •  不思量自难忘°
    2020-12-03 11:55

    Use can use Guzzle Client, it use CURL library but more simple and optimized.

    installation:

    composer require guzzlehttp/guzzle
    

    example in your case:

    // create guzzle object
    $client = new \GuzzleHttp\Client();
    
    // send request
    $response = $client->head("https://example.com");
    
    // extract headers from response
    $headers = $response->getHeaders();
    

    Fast and easy.

    Read more here

提交回复
热议问题