note 61183 added to function.mysqli-multi-query
| From: | Nick at osu1 dot php dot net | Date: | Fri, 27 Jan 2006 16:11:32 +0000 |
| Subject: | note 61183 added to function.mysqli-multi-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102567@lists.php.net to get a copy of this message | ||
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";
?>
----
Server IP: 216.194.113.175
Probable Submitter: 24.153.221.141 (proxied: 192.168.0.74)
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-multi-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61183
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61183&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61183&report=yes
Search -- http://master.php.net/manage/user-notes.php