mysql - PHP PDO: how does re-preparing a statement affect performance -
I am writing a quasi-basic database wrapper class and want to create a leaking method that automagically : This should be prepared for each separate statement only for the first time and will force and execute the query continuously on the call.
I think the main question is: How is it reproduced in the work of the MySql statement, whether the PDO has magically accepted this statement (so I do not have to ) And end the operation?
If I do not , I get it by creating a unique key for each individual query and make a statement prepared in a personal array in the database object - its Under the unique key, I am planning to get array keys in one of the following ways (none of which I like). In order of preference:
- Programmer an additional, always pass the same parameter when the method is called - something on the pattern of
basename (__ FILE__, ".php"). __LINE __
(This method works only when our method is called within a loop - which is most of the time this functionality is required) - Programmer passes completely random
- Use the passed query to generate the key - the hash of a query or something like that
- Get the same as the first bullet ( On)
debug_backtrace
Do you have any experience? Although I am working for does make some noticeable for system optimization (it is big enough and growing by the week), maybe I'm worried about nothing and what I I'm doing, m doing?
Ok, because I'm slowing down the methods for keying queries for query string I myself have done a naive benchmark, using the following plain query string vs. vs. vs. first MD5 hash:
$ php -v $ PHP 5.3.0-3 Sohosine-Patch (CLI) (Created: 26th August 2009 08: 01: 52) $ ... $ php benchmark.php $ PHP hashing: 0.19465494155884 [microgramme] $ MD5 hashing: 0.57781004905701 [micromet] $ 7 99994
Code:
& lt ;? Php error_reporting (E_ALL); $ Queries = array ("SELECT", "INSERT", "UPDATE", "DELETE",); $ Query_length = 256; $ Num_queries = 256; $ Iter = 10000; ($ I = 0; $ i <$ q = int ("", array_map ("chr" A ")), array_fil (0, $ query_length, ord (" z "))))); $ Queries [] = $ q; } Counting count ($ query), "\ n"; $ Cache = array (); $ Side_effect1 = 0; $ T = microtom (true); ($ I = 0; $ i & lt; $ iter; $ i ++) {foreach (dollar query as $ query) {if (! Isset ($ cache [$ q])) {$ cache [$ q ] = $ Q; } And {$ side_effect1 ++; }}} Echo micromet (true) - $ t, "\ n"; $ Cache = array (); $ Side_effect2 = 0; $ T = microtom (true); {Foreach ($ q as $ q) {$ md5 = md5 ($ q) for ($ I = 0; $ i & lt; $ iter; $ i ++); If ($ Asset ($ cache [$ MD5])) {$ cache [$ MD5] = $ q; } And {$ side_effect2++; }}} Echo micromet (true) - $ t, "\ n"; Echo $ side_effect1 + $ side_effect2, "\ n";
Comments
Post a Comment