views:

88

answers:

3

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.

+1  A: 

You can go for the XDebug.

Sarfraz
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
@cdecker: It is php solution, on that paging there is a heading reading **Profiling PHP Scripts**
Sarfraz
*Profiling PHP Scripts* is not the same as profiling webpage load times.
Gordon
A: 
$start=microtime(1);
copy($url,"/dev/null");
echo "$url page loading time is: ".round(microtime(1)-$start,4);

?

Col. Shrapnel
+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
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
@cdecker well, ask them how they do it then. Worst thing that can happen is they don't respond at all.
Gordon
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