Reputation: 153
I want to find how much time a PHP http request spends in Database. Rails logger prints out such information (how much time is spent on rendering, database and app). Example:
Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
Is there something similar for PHP too?
Thanks in advance.
Upvotes: 1
Views: 2315
Reputation: 57184
You can use microtime() and memory_get_usage() to test the speed as well as the memory used (which is often more important with ORM's).
$time = microtime(TRUE);
$memory = memory_get_usage();
...code here...
print (microtime(TRUE)-$time). ' seconds and '. (memory_get_usage()-$memory). ' bytes';
However, database queries should be benchmarked at the database level. Use MySQL Query Profiler for real benchmarking.
Upvotes: 3
Reputation: 52372
Yes, PHP has frameworks (Rails is a framework written in Ruby, PHP is a language) that have built in logging of how much time is spent on things like that. Look at Symfony, Kohana, Zend Framework, CodeIgniter.
Upvotes: 0
Reputation: 2156
Check out the PHP function microtime() http://php.net/manual/en/function.microtime.php I think this is what you're looking for, though I'm not sure.
Upvotes: 1
Reputation: 108
You can use microtime to get the time before the query then subtract it from the time when the query finishes. http://php.net/manual/en/function.microtime.php
Upvotes: 1