Git Product home page Git Product logo

php-get-headers's Introduction

php-get-headers

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

INPUT/OUTPUT

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('https://www.iplocality.com/'); //get headers via CURL

$headers = $h->get_shell_headers('https://preproxy.com/'); //get headers via Linux Shell

$headers = $h->get_headers('http://www.google.com/'); //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.

/home/vagrant/Code/getHeaders.class.php:251:
array (size=10)
  'REQUEST WEBSITES           ' => string 'PHP CURL              LINUX SHELL           PHP GET HEADERS     ' (length=64)
  'https://www.google.com/    ' => string '1.8369688987732       1.4304299354553       1.1995270252228     ' (length=64)
  'https://www.bing.com/      ' => string '0.96593499183655      0.98185205459595      0.92472505569458    ' (length=64)
  'http://www.yahoo.com/      ' => string '0.59260082244873      0.35894203186035      2.4568209648132     ' (length=64)
  'http://www.preproxy.com/   ' => string '1.1098358631134       0.35897588729858      1.6951670646667     ' (length=64)
  'http://www.iplocality.com/ ' => string '0.71652007102966      0.72328615188599      0.82622981071472    ' (length=64)
  'http://www.facebook.com/   ' => string '0.73158597946167      0.81967496871948      2.4969518184662     ' (length=64)
  'http://www.youtube.com/    ' => string '0.58801817893982      1.0290570259094       1.3727321624756     ' (length=64)
  'http://www.twitter.com/    ' => 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

php-get-headers's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

dalaolala

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.