PHP Classes

PHP HTTP Headers Information: Get the headers of HTTP response of a given URL

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-05-30 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 126 This week: 3All time: 8,780 This week: 137Up
Version License PHP version Categories
php-get-headers 1.0.0GNU General Publi...5HTTP, PHP 5
Description Author

This class can get the headers of HTTP response of a given URL.

It can send HTTP requests to a given URL using several means like using the CURL extension, or the curl command via shell script or the PHP get_headers function.

The class returns an array as a list of headers retrieved as response of the HTTP request.

Name: Waqar A <contact>
Classes: 2 packages by
Country: United Kingdom United Kingdom
Age: ???
All time rank: 3241138 in United Kingdom United Kingdom
Week rank: 104 Up5 in United Kingdom United Kingdom Up


Class to get HTTP headers using Linux shell, CURL or PHP function get_headers.
Class to get http headers using diffrent methods available in PHP

Takes URL as argument
Contains 3 diffrent methods to get http headers #1. PHP CURL, #2. Linux shell via PHP shell_exec, #3. PHP function get_headers()
all get header methods return an array of all headers
first element of array contains int http response code

makes http request to a URL return http response headers @return array of headers @param (mac , pc, mobile): optional user-agent param to change CURL user-agent

Use Cases

Check if a web site is up
Use crontab to make http requests periodically to the website you want to monitor, send alert if http response code is not 200
Make sure URL is up before making file_get_contents
Make a headers request to ensure webpage exists, befor making PHP's file_get_contents or fopen calls.

Usage Example
$h = new GetHeaders('mac'); //sets CURL's user-agent to Mac

$h = new GetHeaders(); //Keeps default user-agent

$headers = $h->get_curl_headers(''); //get headers via CURL

$headers = $h->get_shell_headers(''); //get headers via Linux Shell

$headers = $h->get_headers(''); //get headers via PHP function get_headers

Benchmark speed of diffrent get_http_headers methods
Class contains benchmark method with some URLs to test all get header methods. Use your own array of URLs to benchmark performance.

array (size=10)
  'REQUEST WEBSITES           ' => string 'PHP CURL              LINUX SHELL           PHP GET HEADERS     ' (length=64)
  '    ' => string '1.8369688987732       1.4304299354553       1.1995270252228     ' (length=64)
  '      ' => string '0.96593499183655      0.98185205459595      0.92472505569458    ' (length=64)
  '      ' => string '0.59260082244873      0.35894203186035      2.4568209648132     ' (length=64)
  '   ' => string '1.1098358631134       0.35897588729858      1.6951670646667     ' (length=64)
  ' ' => string '0.71652007102966      0.72328615188599      0.82622981071472    ' (length=64)
  '   ' => string '0.73158597946167      0.81967496871948      2.4969518184662     ' (length=64)
  '    ' => string '0.58801817893982      1.0290570259094       1.3727321624756     ' (length=64)
  '    ' => string '0.66506004333496      0.47173810005188      3.1517231464386     ' (length=64)
  'AVERAGE SPEED              ' => string '0.90081560611725      0.77174451947212      1.7654846310616     ' (length=64)
PHP function get_headers is slowest, while linux shell and CURL are much faster. However when requesting secure https header PHP functions tend to perform better. Try and see if you get same results
  Files folder image Files  
File Role Description
Plain text file getHeaders.class.php Class Class source
Accessible without login Plain text file Doc. Documentation
Accessible without login Plain text file readme.txt Doc. Read Me Documentation

 Version Control Unique User Downloads Download Rankings  
This week:3
All time:8,780
This week:137Up