Merge pull request #351 from ulvii/sqlsrvConnPoolTest

Adding a script to test sqlsrv connection pooling on Linux and Mac
This commit is contained in:
Jenny Tam 2017-04-03 13:06:02 -07:00 committed by GitHub
commit 749f150be8
3 changed files with 61 additions and 1 deletions

View file

@ -22,7 +22,7 @@ print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));
//disable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current = str_replace("CPTimeout=5\n[ODBC]\nPooling=Yes\n",'',$current);
$current = str_replace($lines_to_add,'',$current);
file_put_contents($odbcinst_ini, $current);
print_r(shell_exec("php ./test/pdo_sqlsrv/isPooled.php"));

25
test/sqlsrv/isPooled.php Normal file
View file

@ -0,0 +1,25 @@
<?php
include_once 'autonomous_setup.php';
$conn1 = sqlsrv_connect( $serverName, $connectionInfo);
$connId1 = ConnectionID($conn1);
sqlsrv_close($conn1);
$conn2 = sqlsrv_connect( $serverName, $connectionInfo);
$connId2 = ConnectionID($conn2);
if ($connId1 === $connId2){
echo "Pooled\n";
}else{
echo "Not Pooled\n";
}
function ConnectionID($conn)
{
$tsql = "SELECT [connection_id] FROM [sys].[dm_exec_connections] where session_id = @@SPID";
$stmt = sqlsrv_query($conn, $tsql);
sqlsrv_fetch($stmt);
$connID = sqlsrv_get_field($stmt, 0);
sqlsrv_free_stmt($stmt);
return ($connID);
}
?>

View file

@ -0,0 +1,35 @@
--TEST--
SQLSRV Connection Pooling Test on Unix
--DESCRIPTION--
This test assumes odbcinst.ini has not been modified.
This test also requires root privileges to modify odbcinst.ini file on Linux.
--SKIPIF--
<?php if(PHP_OS === "WINNT") die("Skipped: Test for Linux and Mac");?>
--FILE--
<?php
$lines_to_add="CPTimeout=5\n[ODBC]\nPooling=Yes\n";
//get odbcinst.ini location
$lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
//enable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current.=$lines_to_add;
file_put_contents($odbcinst_ini, $current);
//Creating a new php process, because for changes in odbcinst.ini file to affect pooling, drivers must be reloaded.
print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
//disable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current = str_replace($lines_to_add,'',$current);
file_put_contents($odbcinst_ini, $current);
print_r(shell_exec("php ./test/sqlsrv/isPooled.php"));
?>
--EXPECT--
Pooled
Not Pooled