开发者

How to measure speed of php scripts independantly of eachother? Various Methods?

On my website various php codes run from various programmers from whom I have bought project scripts. Some use a session ( sessi开发者_开发问答on start etc...) Some use external include php files and do their math within there and return or echo some things. Some run only when asked to, like the search script.

Is there an easy way for me to monitor, temporary, all the various scripts's their delays in millisecond sothat I can see whats going on below the water?

I have seen once a programmer making something and below the page there were these long listst of sentences and various ms numbers etc.

Q1. Is there a default php function for this? How do I call/toggle this?

Q2. What are the various methods with which such calculations are made?

Q3. How reliable are they? are those milliseconds theory or actual real world result?

Thanks for your insight! Sam


No defualt method i can thnik of. But its easy.At the start of your script simply place this:

$s = microtime(true);

and at the end

$e = microtime(true);
echo  round($e - $s, 2) . " Sec";

Normally you would leave the second parameter of round() as it is, but if you find that your script reports the time as ’0 Sec’ increase the number until you get an answer.check this for more


If you're running an Apache webserver, then you should have the apache benchmarking tool that can give some very accurate information about script timings, even simulating numbers of concurrent users.

From a web browser, the Firebug extension of Firefox can also be useful as a tool for seeing how long your own requests take.

Neither of these methods is purely a timer for the PHP code though


The easiest/fastest way is to install a debugging extension that supports profiling, like XDebug. You can then run a profiling tool (e.g.: KCachegrind) to profile your scripts, graph the results, and figure out what uses the most memory, execution time, etc.

It also provides various other functionalities like stack tracing, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜