-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmysql-example.php
More file actions
31 lines (22 loc) · 767 Bytes
/
Copy pathmysql-example.php
File metadata and controls
31 lines (22 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
use AsyncMySQL\MySQLPool;
require_once __DIR__ . "/src/Async.php";
require_once __DIR__ . "/src/AsyncMySQL/MySQLPool.php";
header("content-type: text/plain");
// Top-level Fiber (equivalent to top-level async/await in JavaScript)
$main = new Fiber(function(){
$mysqlPool = new MySQLPool(10, "localhost", "root", "", "test");
$queryFiber = new Fiber(function() use ($mysqlPool){
$result = Async::await($mysqlPool->execute(
"SELECT * FROM test_table WHERE `id` = :id",
[":id"=>1]
));
// Will return as soon as this query is done and does not wait on others
print_r($result);
});
$queryFiber->start();
// Hold here until all async operations are done
Async::run();
});
// Start the top-level Fiber
$main->start();