Closed Voltara closed 10 years ago
PDO documentation says that the timeout should be set in seconds. PDO::ATTR_TIMEOUT (integer) Sets the timeout value in seconds for communications with the database.
http://www.php.net/manual/en/pdo.constants.php
The pdo_cassandra driver implements the PDO interface.
I should clarify this bug report with some example code. This script attempts to connect to Cassandra with a 10 second timeout.
$t0 = microtime(true);
try {
/* Connect with a timeout of 10 seconds */
$dbh = new PDO('cassandra:host=10.250.29.207', 'cassandra', 'cassandra',
array( PDO::ATTR_TIMEOUT => 10 ));
echo "Connection OK\n";
} catch (PDOException $e) {
echo 'Connection failed: ', $e->getMessage(), "\n";
}
$t1 = microtime(true);
printf("Elapsed time: %.3f seconds\n", $t1 - $t0);
Now I tell Linux to simulate a 0.1 second network delay:
$ sudo tc qdisc add dev eth0 root netem delay 100ms
$ ping -c3 10.250.29.207
PING 10.250.29.207 (10.250.29.207) 56(84) bytes of data.
64 bytes from 10.250.29.207: icmp_seq=1 ttl=64 time=100 ms
64 bytes from 10.250.29.207: icmp_seq=2 ttl=64 time=100 ms
64 bytes from 10.250.29.207: icmp_seq=3 ttl=64 time=100 ms
Here's what happens when I try to run my test script:
$ php cassandra_timeout.php
Connection failed: CQLSTATE[08006] [8] TTransportException: Transport not open
Elapsed time: 0.011 seconds
The connection timed out after 0.01 seconds instead of 10 seconds.
Forgot to include the command to remove the 100ms delay from the kernel:
$ sudo tc qdisc del dev eth0 root netem delay 100ms
(Just change "add" to "del".)
PDO documentation specifies PDO::ATTR_TIMEOUT as an integer number of seconds. The YACassandraPDO driver is treating the value as milliseconds.
Also, it seems supplying a value for PDO::CASSANDRA_ATTR_CONN_TIMEOUT in the constructor's $driver_options array has no effect.