Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Logging query time

posted by jmtucu 8 years ago

Hi! I need to logging the running time of a query, similar to the result of $db->enableDebugging(true), for example i've this:

$db = fORMDatabase::retrieve(__CLASS__);
$rows = $db->query('SELECT * FROM users WHERE statu = %i', $status);

I saw a $query_time in the fDatabase class but is private. Actually I'm using microtime() before and after the sentence but's really annoying. There's something like $rows->getQueryTime() ?


jmtucu, I would open a ticket for perhaps adding the getQueryTime() functionality as I'm fairly sure it doesn't exist. It would likely be pretty visible in the API. Microtime is the right way to do it, however, as you have pointed out, it's annoying to wrap every query with it, but more than that, query() itself if I'm not mistaken has quite a bit of additional processing, which means the times reported are not 100% accurate.

Instead of querying the time for the query itself you're getting the query + all the pre and post-processing of Flourish. If you want the exact query time it would be best to have it wrapped around the actual final query call within Flourish.

It would likely be easy enough to add in a fork if this is for a particular project. But, as I said, opening a ticket will likely get it included unless there's some major reason why it doesn't make sense. I'm just not sure it's particularly useful in a number of cases. Outside of benchmarking, what is the reasoning for it?

posted by mattsah 8 years ago

Thanks msahagian por answer!

I need it for benchmarking and audit. If you do not consider it useful, I added the method to my project for my own :)

Actually I'm using a custom class made by me (fTimer) using microtime().

posted by jmtucu 8 years ago

You can grab the query time of a query by using the fDatabase#Hooks.

posted by wbond 8 years ago

That's why I love you :P

Thanks again Will!

posted by jmtucu 8 years ago