Author: Waqar Ahmed
Updated on: 2021-03-16
Posted on: 2021-03-16
Viewers: 278 (March 2021 until December 2021)
Last month viewers: 1 (December 2021)
Package: PHP HTTP Headers Information
One way to perform such kind of check is to send a HTTP request to the site URL and verify if it responds the way that it is expected when the site is working well.
Read this short tutorial article to learn how to quickly check a remote site retrieving the HTTP header responses.
How to Retrieve HTTP Response Headers from a Remote Site in PHP
PHP has a function for getting the response headers when it accesses a given URL. We can also use other methods like PHP curl extension functions to get the same response headers. The speed of access varies between methods and the type of connection: secure or standard.
The PHP HTTP Headers Information class implements three functions to retrieve the HTTP response headers in an array with HTTP status response code.
Which Solution Can Be Better to Get the HTTP Response Headers
The class that I am presenting here also contains a benchmark method to measure the performance of all these methods. It turns out using the curl extension or a Linux shell command can be faster than using the PHP get_headers function.
However, if you want to check a secure site using URL based on https, then using PHP get_headers does better job.
So you can chose a better method depending on the URL you want to check to achieve better performance.
Besides encapsulating the access the HTTP response headers, this class also use three user agents to access the remote site: mobile, Mac, PC using Windows.
So when you use curl extension or the Linux shell command, the user-agent can be set according to your interests, as some Web sites might respond differently when the user agent is not a regular Web browser.
To evaluate each of the methods and options that the class provides, you can try using the class benchmark method.
Download or Install the PHP HTTP Headers Information package using Composer
This package can be downloaded in compressed archive in ZIP or tar.gz format by going to the download page.
You can also install it in projects managed using the PHP Composer tool by following the instructions in this page.
You need to be a registered user or login to post a comment
1,590,326 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
No comments were submitted yet.