note 61183 deleted from function.mysqli-multi-query by hholzgra
| From: | hholzgra@php.net | Date: | Sat, 29 Sep 2007 11:44:16 +0000 |
| Subject: | note 61183 deleted from function.mysqli-multi-query by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-130921@lists.php.net to get a copy of this message | ||
Note Submitter: Nick
----
I assume this is here for performance, to avoid having to establish a communication link over the
network repeatedly. My tests reveal some serious overhead though.
Communicating on an internal network at 100Mbps I had to combine over 300 queries to see a speed
increase, and under that it was faster to do them individually.
I wouldn't recommend using this to combine 3 or 4 queries if all you're after is speed. It
may be more worthwhile if your database calls have to go out over the internet.
Here's the benchmark I used:
<?php
$reps = 100;
$db = new mysqli("yourserver.com", "username", "password",
"dbname");
$query = "SELECT column FROM table WHERE id=1";
$start = microtime();
for ($i = 0; $i < $reps; $i++) {
$result = $db->query($query);
$result->close;
}
$end = microtime();
echo ($end - $start) . "<br>\n";
$start = microtime();
for ($i = 0; $i < $reps; $i++) {
$myquery .= $query . "; ";
}
$db->multi_query($myquery);
do {
$result = $db->store_result();
$result->close;
} while ($db->next_result());
$end = microtime();
echo ($end - $start) . "<br>\n";
?>