How to know php script load time hosted locally - php

I have a website developed with PHP from scratch, and I want to know the load time of my php script (my page) in localhost.
is there any method or tools to check that ? I try to use Performance on Google Chrome, but it's very hard to understand, and with some search on Google I found the firebug plugins of firefox, but it's deleted.
is there any solution ?

I you want the mesure the loading time browser-side, as Madhawa commented, you can view it in the network tab of chrome's developer tools :
If you want the exact execution time of your script, it should be done server-side by checking the time before and after the script. Daniels link should point you to the right direction.

<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
echo $start;
?>
Try this

Related

JSON - PHP vs C/C++

I had a site working nicely in PHP. Then an acquaintance who works at Google got in my ear about how AJAX is the thing. So now I've rejigged the site to be in just HTML & javascript on the client-side making AJAX JSON calls to PHP scripts calling MySQL on the server side. Good caching, no page reloads. It was a good idea.
My question now, however, is this: How much faster might the site run if the server side was in a compiled language (say, C or C++) rather than PHP? (My original prototype was in C - in the terminal!) The PHP scripts are all basic security processing and then database calls to return JSON. How can you benchmark relative speeds? Just using firebug POST data in the console? Or is there a better way?
Thanks :)
if it is that simple, php interpretation will be a tiny fraction of the execution time, most of which will be taken by the connection to the db server. You can always look at Facebook's HipHop - http://developers.facebook.com/blog/post/358/ though
For benchmarking, something like
// first line of your code
$start_time = microtime( $get_as_float = TRUE );
// last line of your code
$time_end = microtime( $get_as_float = TRUE );
$execution_time = $time_end - $start_time;
echo '<!-- executed in: ', $execution_time , ' seconds -->';
will go a long way
I wouldn't use the times in Firebug as those depend on your connection speed/quality etc

Page Speed - Test Script response speed

I made a website recent and it's loading very slow. My Firebug Page Speed Score is 82/100. I think this is good. My website has 2 images and they have 100KB and some other small images for bullets, arrows and stuff that have not more that 50KB.
Anyway, my point is that the html is quite fast, but I have this html as a Wordpress theme and a new host (cheap one).
My question: How can I find the time for my Wordpress (or any PHP script) to echo out the page requested.
Can I know for sure if the hosting or the script that is making my page work slow?
Thank you!
time your script?
<?php
$start = microtime(true);
//your script here
$end = microtime(true);
$time = $end - $start;
echo('script took ' . $time . ' seconds to execute.');
?>
I use Fiddler for this. It is a handy tool that can accurately time the entire request and response, to and from the server.
Just open Fiddler, go to your site, select all of the requests related, and click the statistics tab.

Eclipse PHP Profiler - How Do You Get Parameters?

Using Eclipse's PHP Profiler, I have discovered a bottleneck in my code on a method that is called many times. The problem is that I cannot tell what parameters were passed in to the method to determine how to reproduce the symptom.
I have tried surrounding the code that the profiler is reporting as taking a full second to complete with the following:
$startTime = microtime(true);
$safe_text = wp_check_invalid_utf8( $text );
$endTime = microtime(true);
$time = $endTime - $startTime;
if ($time > .05) {
error_log('Time: ' . $time . ' text [' . $text . ']');
}
I never have a single hit in the error log for this, yet the profiler will continue to report one as taking a full second to complete. Refreshing the page in the browser does indicate that there is significant slowness.
I have this same problem in 3 different areas of my code and knowing what was being passed in to the methods at the time they run slowly may be of assistance in fixing the problem. Is there any way to determine what is being passed in to the intermittently slow method when it is running slowly?
It is possible to set this up using xdebug which is what Eclipse uses for profiling, however it's disabled by default because recording this data in a project that makes a lot of calls or passes large data structures would quickly overwhelm your available memory.
I recommend you do manual logging as you are currently doing although I'd start by measuring the total time of all calls to wp_check_invalid_utf8 to make sure you do infact have a problem in just that part and that is isn't just a problem caused by the Eclipse profiler itself. Once you've established the total time is more than you would like, then start logging individual calls and their parameters.

Testing server load time with PHP?

Is there a way to determine how long it takes a web page, and all it's content, to load with PHP?
I have already tried this:
$time_start = microtime(true);
(All the content of the web page here)
$time_end = microtime(true);
$time = $time_end - $time_start;
echo $time;
However, the problem with this (as far as I can tell) is that I'm only calculating the time it takes the php script to execute. This doesn't factor in any images or videos that are on the page.
Is there a way to determine how long it takes a web page to load including images or videos using php?
Basically what I'm trying to do is test the speed of my server with out factoring in my connection speed.
You need to download firebug and then open the "net" tab and wait for the page to finish loading and it will show you the total load time of all requests.
You might consider ab (ApacheBench). It's for testing the performance of your web server, but you can run it against a particular URL if you're just concerned about one page. One advantage is that it can run from the command line and issue multiple requests in parallel, enabling you to do some kind of load testing.
If you want to factor in how long it takes to actually load on the browser, you'll need some kind of javascript solution. One approach with code is presented in the article, Optimizing Page Load Time, which is worth reading.
Google Chrome has an amazing Audit tool built in which gives a good list of ways to improve a given site as far as speed goes.
alt text http://far.id.au/audit.png
try this
// top of the page --
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
?>
// end of the page --
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>
You can either use the NavigationTiming API (https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming2/Overview.html) and beacon the timings back - this is how boomerang works (https://github.com/lognormal/boomerang)
Alternatively use a synthetic test tool like webpagetest.org to gather timings from various browsers/locations/network variations

Log/Graph PHP execution time

Are there any tools available to log the page load time for a php site?
Mainly looking for something that I can see trends of load times over time, I was considering dumping them into a file using error_log(), but I don't know what I could use to parse it and display graphs
You can record the microtime at the start of execution, hold that variable until the end, check the time, subtract them, and there you have your execution time. Output buffering will be required to make this work in most cases, unless it's a situation in which a particular thing always runs last (like footer()).
$time_start = microtime_float();
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//at the start.
//at the end:
$time_end = microtime_float();
$time = round($time_end - $time_start, 4);
echo "Last uncached content render took $time seconds";
Use the Firebug extension for Firefox, it has a Net panel that shows you load times.
If you want to do load testing, apache comes with a utility called apache bench, try ab --help in a console window near you.
See PEAR Benchmark. It allows you to add benchmarks into your code. You can have it dump an HTML table on your pages, or you can loop through the data and write to a log file.

Categories