如何使用 PHP 获取服务器响应时间 [英] How to get server response time using PHP

查看:114
本文介绍了如何使用 PHP 获取服务器响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个 php 脚本来检查来自另一台服务器的正常 HTTP 响应,例如 http://www.example.com,一个状态脚本,用于查看其他服务器的行为是否正常.

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.

有人可以帮我吗?

推荐答案

借助 php 中的 cURL,您可以轻松完成.您可以发送请求并查看请求的确切时间.

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);
?>

这篇关于如何使用 PHP 获取服务器响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆