Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get server response time using PHP

Tags:

php

server

I needed a script in php that checked for a normal HTTP response from another server like http://www.example.com, a status script to see if the other server(s) where behaving as they should.

Anybody can help me?

like image 544
user3305431 Avatar asked Dec 03 '15 07:12

user3305431


1 Answers

You can do simply with help of cURL in php. You can send request and view exact time of request.

<?php
  if(!isset($_GET['url']))
  die("enter url");
  $ch = curl_init($_GET['url']); //get url http://www.xxxx.com/cru.php?url=http://www.example.com
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  if(curl_exec($ch))
  {
  $info = curl_getinfo($ch);
  echo 'Took ' . $info['total_time'] . ' seconds to transfer a request to ' . $info['url'];
  }

  curl_close($ch);
?>
like image 104
Nandu Avatar answered Oct 08 '22 12:10

Nandu