msphpsql: Connection pooling does not work within Linux
We have just installed the latest SQL 13 drivers and the latest sqlsrv and sqlsrv_pdo PHP extensions. Connection pooling does not seem to be working.
- OS: CentOS 7.2
- PHP: PHP 7.0.12
- SQL Driver: ODBC Driver 13 for SQL Server
Summary of test: We created a test script which will connect to the DB. After the script executes the connection is closed, confirmed by the DB.
odbcinst.ini:
[ODBC]
Pooling = Yes
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
UsageCount=1
CPTimeout=120
Test script which includes some timing:
$startTime = microtime(true);
function printElapsedTimeSinceLastEvent($event=''){
global $startTime;
$elapsed = microtime(true) - $startTime;
echo $event . round($elapsed*1000) ."\n";
$startTime = microtime(true);
}
// Connection sqlsrv driver
$pdo = new PDO ("sqlsrv:server=10.12.12.123;database=aDatabaseName",'coolUser','someAwesomePassword');
printElapsedTimeSinceLastEvent("Connected: ");
$stmt = $pdo->prepare("SELECT TOP 10 * FROM users");
$stmt->execute();
printElapsedTimeSinceLastEvent("Execute: ");
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
printElapsedTimeSinceLastEvent("Fetch: ");
3 consecutive outputs of script:
Connected: 149
Execute: 109
Fetch: 2
Connected: 149
Execute: 100
Fetch: 2
Connected: 152
Execute: 108
Fetch: 2
Using SQL Studio and running EXEC sp_who2 we can see the connections are closed after each run. Using sqlsrv on Windows does keep connections open as expected and does show up in sp_who2 output.
On Windows where we confirmed connection pooling does exist the connection time is significantly faster as one would expect with connection pooling.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (10 by maintainers)
@sean256 Just an update: we are working on a fix for this. We will be completing the fix and testing it in the next 1-2 weeks. If the results are as expected we will release it in our next preview release.
@sean256 the 4.1.6 release on github or the 4.1.6.1 release on PECL enables connection pooling for unixODBC 2.3.1. The readme and changelog contains a list of limitations or issues you may encounter when you use connection pooling.
By default connection pooling is disabled. To enable, in odbcinst.ini, add
Pooling=Yesto the[ODBC]section and a positiveCPTimeoutvalue to[ODBC Driver 13 for SQL Server]section. So minimally it should look like:See http://www.unixodbc.org/doc/conn_pool.html for detailed instructions.
Enabling connection pooling with unixODBC 2.3.4 will not work with pdo_sqlsrv but we have it on our backlog to fix.
@meet-bhagdev It was my script and I have tried that with no luck. I had tried that variant before posting when I was just thrashing for a solution.
I’m not familiar with the inner workings of ODBC at all but the ODBC docs do state Pooling should be under [ODBC]. I still tried it in both places with no luck.
It also states CPTimeout should live under the DSN. Is that an ODBC specific property or is it something that each drive much implement?