note 115424 added to mysqli.poll
| From: | l_sanczyk at hotmail dot com | Date: | Mon, 21 Jul 2014 19:56:28 +0000 |
| Subject: | note 115424 added to mysqli.poll | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200003@lists.php.net to get a copy of this message | ||
You can use the following code to execute, for example, 10 simultaneous queries:
$query = "SELECT
field1, field2 FROM table WHERE
field1='something'";
$all_links = array();
for($i=0; $i<10; $i++) {
$link =
mysqli_connect("your.mysql.server.here","your@user","pa$$w0rd",DataBase_Name");
$link->query($query, MYSQLI_ASYNC);
$all_links[] = $link;
}
$processed = 0;
do {
$links = $errors = $reject = array();
foreach ($all_links as $link) {
$links[] = $errors[] = $reject[] = $link;
}
if (!mysqli_poll($links, $errors, $reject, 1)) {
continue;
}
foreach ($links as $link) {
if ($result = $link->reap_async_query()) {
print_r($result->fetch_row());
if (is_object($result))
mysqli_free_result($result);
} else die(sprintf("MySQLi Error: %s", mysqli_error($link)));
$processed++;
}
} while ($processed < count($all_links));
NOTE: If you get a "Warning: mysqli::query() expects parameter 2 to be long, string given"
you have a mysqlnd installation or configuration issue.
----
Server IP: 72.52.91.14
Probable Submitter: 190.229.198.104
----
Manual Page -- http://php.net/manual/en/mysqli.poll.php
Edit -- https://master.php.net/note/edit/115424
Del: integrated -- https://master.php.net/note/delete/115424/integrated
Del: useless -- https://master.php.net/note/delete/115424/useless
Del: bad code -- https://master.php.net/note/delete/115424/bad+code
Del: spam -- https://master.php.net/note/delete/115424/spam
Del: non-english -- https://master.php.net/note/delete/115424/non-english
Del: in docs -- https://master.php.net/note/delete/115424/in+docs
Del: other reasons-- https://master.php.net/note/delete/115424
Reject -- https://master.php.net/note/reject/115424
Search -- https://master.php.net/manage/user-notes.php