-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_mysql_timeout.php
More file actions
42 lines (37 loc) · 930 Bytes
/
Copy pathtest_mysql_timeout.php
File metadata and controls
42 lines (37 loc) · 930 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
32
33
34
35
36
37
38
39
40
41
42
<?php
require 'autoloader.php';
use js\tools\dbhandler\exceptions\DbException;
use js\tools\dbhandler\Handler;
use js\tools\dbhandler\parameters\MySQL;
try
{
// TODO set your own test connection parameters!
$handler = Handler::getConnection('test', MySQL::viaHost('test', 'test', 'test'));
// this is the mysql.ini variable that should be adjusted according to needs
// but it works via query as well
$handler->exec('SET SESSION wait_timeout = 1');
echo 'connection timeout set to 1 second, sleeping', PHP_EOL;
sleep(3);
if ($handler->checkConnection())
{
echo 'connection is good', PHP_EOL;
}
else
{
echo 'connection is down, reconnecting', PHP_EOL;
$handler->connect();
}
if ($handler->checkConnection())
{
echo 'connection is now good', PHP_EOL;
}
else
{
echo 'connection is still down, failed to reconnect', PHP_EOL;
}
}
catch (DbException $e)
{
echo $e->getMessage(), PHP_EOL;
die();
}