I was wondering whether there is a simple PHP library to test the loading speed of a web page or a single resource similar to Google Page Speed and Yahoo! YSlow. The reason is that I'd like to build a web based alternative.
Wow, I didn't expect such a fast answer. But this seems to be more of a C solution, while I'm looking for something more like a pure PHP solution.
cdecker
2010-04-16 12:40:08
@cdecker: It is php solution, on that paging there is a heading reading **Profiling PHP Scripts**
Sarfraz
2010-04-16 12:51:02
*Profiling PHP Scripts* is not the same as profiling webpage load times.
Gordon
2010-04-16 13:35:35
A:
$start=microtime(1);
copy($url,"/dev/null");
echo "$url page loading time is: ".round(microtime(1)-$start,4);
?
Col. Shrapnel
2010-04-16 12:51:40
+1
A:
PageSpeed and YSlow run in the browser and do not only measure loading of one URL, but also of all resources linked on that URL in addition to @import
and url()
directives in CSS files and javascript resources lazy loaded while the DOM is loading. I doubt this can be done easily/at all with PHP without running the code through a server side JS engine as well.
Consider this snippet of Dojo code:
dojo.require("dijit.form.Button");
or this JavaScript code:
document.write('<script src="',
'http://example.com/other.js',
'" type="text/JavaScript"><\/script>');
Given the number of possible approaches out there, this is virtually impossible to catch from PHP. If you still want to try, check out the cURL, DOM and HTTP extension.
Or consider measuring from the browser with JavaScript, e.g. something like http://webwait.com/
Gordon
2010-04-16 13:18:28
Agreed, it won't be easy, but somehow there are sites already doing that, and I don't think they have a browser instance running somewhere.
cdecker
2010-04-16 18:13:57
@cdecker well, ask them how they do it then. Worst thing that can happen is they don't respond at all.
Gordon
2010-04-17 12:48:38
Well as far as I can see there is no simple solution to this problem. My best guess would be to hook into a real webbrowser such as wkhtmltopdf (http://bit.ly/dpubxW) and record loading times.So I guess your answer was the most helpful :D
cdecker
2010-04-17 16:51:10