PHP函数获取页面的文件大小和加载时间 [英] PHP function for getting file size and loading time for a page

查看:108
本文介绍了PHP函数获取页面的文件大小和加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于我的最后一个问题,我想拥有一个可以采用本地路径并告诉我的PHP函数(a)HTML,CSS,JS和图像的总文件大小为多少,以及(b)此页面的总加载时间.我想像YSlow一样,但是作为PHP函数.

Similar to my last question, I'd like to have a PHP function that can take a local path and tell me (a) how much the total file size is for HTML, CSS, JS and images, and (b) the total load time for this page. Like YSlow I think, but as a PHP function.

有什么想法吗?我环顾四周,想知道我是否可以使用CURL?即使我需要检查自己服务器上的路径?谢谢!

Any thoughts? I looked around and was wondering can I use CURL for this? Even though I need to check paths that are on my own server? thanks!

更新:

阅读评论后,意识到我是基地.相反,想知道是否有一种方法可以以编程方式获得页面的YSlow得分(或类似的性能得分).我认为它将需要访问充当客户端的第三方站点.我基本上是试图遍历一组页面并获得某种性能指标.谢谢!

After reading the comments, realizing I'm off base. Instead wondering is there a way programatically get a YSlow score for a page (or similar performance score). I assume it would need to hit a third-party site that would act as the client. I'm basically trying to loop through a group of pages and get some sort of performance metric. Thanks!

推荐答案

用于文件大小.

  • Create a loop to read all files in a specific directory with dir.
  • Then for each file use filesize.

加载时间 加载时间取决于连接速度和文件大小.而且我看到您指定要在本地读取文件.您可以检测读取这些文件需要花费多少时间,但这不会是外部用户页面的加载时间.

Loadtime Loadtime depends on the connection speed and the filesize. And I see that you specify that you are reading locally the files. You can detect how much time it take you to read those files but this will not be the loadtime for the page for an external user.

这篇关于PHP函数获取页面的文件大小和加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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