-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathpdo.phpt
46 lines (42 loc) · 1013 Bytes
/
pdo.phpt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--TEST--
swoole_runtime: pdo
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
skip_if_pdo_not_support_mysql8();
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Swoole\Runtime::enableCoroutine();
$count = 0;
function mysql_sleep(float $time)
{
$pdo = new PDO(
"mysql:host=" . MYSQL_SERVER_HOST . ";port=" . MYSQL_SERVER_PORT . ";dbname=" . MYSQL_SERVER_DB . ";charset=utf8",
MYSQL_SERVER_USER, MYSQL_SERVER_PWD
);
$pdo->exec("SELECT sleep({$time})");
if (Assert::assert($pdo->errorCode() === PDO::ERR_NONE)){
global $count;
$count++;
}
}
function onRequest()
{
mysql_sleep(.1);
}
$start = microtime(true);
for ($i = MAX_CONCURRENCY_LOW; $i--;) {
go('onRequest');
}
Swoole\Event::wait();
Assert::same($count, MAX_CONCURRENCY_LOW);
Assert::assert((microtime(true) - $start) < .5);
//关闭协程,否则会致命错误
Swoole\Runtime::enableCoroutine(false);
mysql_sleep(.1); //block IO
echo "DONE\n";
?>
--EXPECT--
DONE