Created
May 30, 2013 13:27
-
-
Save ThomasWeinert/5677795 to your computer and use it in GitHub Desktop.
Asynchronous MySQL queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('../../src/Carica/Io/Loader.php'); | |
Carica\Io\Loader::register(); | |
use Carica\Io; | |
$mysqlOne = new Io\Deferred\MySQL(new mysqli('127.0.0.1')); | |
$mysqlTwo = new Io\Deferred\MySQL(new mysqli('localhost')); | |
$time = microtime(TRUE); | |
$queries = Io\Deferred::When( | |
$mysqlOne("SELECT 'Query 1', SLEEP(5)") | |
->done( | |
function($result) use ($time) { | |
var_dump(iterator_to_array($result)); | |
var_dump(microtime(TRUE) - $time); | |
} | |
), | |
$mysqlTwo("SELECT 'Query 2', SLEEP(2)") | |
->done( | |
function($result) use ($time) { | |
var_dump(iterator_to_array($result)); | |
var_dump(microtime(TRUE) - $time); | |
} | |
) | |
); | |
$loop = Io\Event\Loop\Factory::get(); | |
Io\Event\Loop\Factory::run($queries); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment