Description
PHP Driver version or file name
5.9.0
SQL Server version
Microsoft SQL Server 2019 (RTM-CU8-GDR) (KB4583459) - 15.0.4083.2 (X64)
Client operating system
RHEL 7.8
Kernel: Linux 3.10.0-1127.18.2.el7.x86_64 x86_64
PHP version
7.4.16 NTS (7.4.16-1.el7.remi)
Microsoft ODBC Driver version
Microsoft ODBC Driver for SQL Server 17.7.1.1 (msodbcsql17.x86_64 17.7.1.1-1)
unixODBC 2.3.7 (unixODBC.x86_64 2.3.7-1.rh)
Table schema
N/A
Problem description
Reloading Apache during a long-running query causes the next query to be executed after child processes come back to generate the following error:
SQLSTATE[08S01]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2714
Occasionally this error occurs instead:
SQLSTATE[08S01]: [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure
Expected behavior and actual behavior
The next query should succeed.
Repro code or steps to reproduce
Create a script with the following:
$pdo = new PDO( 'sqlsrv:Server=server; LoginTimeout=15; MultipleActiveResultSets=false', '', '', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ] );
$pdo->query( "WAITFOR DELAY '00:00:05'" );
var_dump( $pdo->query( 'SELECT 1 AS Row1' )->fetchAll( PDO::FETCH_ASSOC ) );
Save the script in a location that can be served up by Apache (httpd24-httpd.x86_64 2.4.34-18.el7 in my case) and executed by PHP.
For example: http://localhost/test.php
Continually refresh the page after after it has been served (will take a minimum of 5 seconds due to the WAITFOR).
Reload the Apache service. My RHEL installation required /bin/systemctl reload httpd24-httpd.service
.
Once child processes are back, reloading the page (executing the script) will generate the error stated above.
The issue only seems to happen when using PDO_SQLSRV and not any other PDO driver.
For example, I've tried the following and was unable to reproduce:
new PDO( 'odbc:server', '', '' )
- using PDO_ODBC insteadnew PDO( 'dblib:server', '', '' )
- using FreeTDS
Tried the following but the issue still occurred:
- Disabling pooling
- Restarting Apache service instead of reloading (
/bin/systemctl restart httpd24-httpd.service
) - ConnectRetryCount > 1 in the DSN (I believe this is Windows only though so no surprise there)
odbcinst -j
output:
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/user/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Relevant section of odbcinst.ini:
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.7.so.1.1
UsageCount=1
CPTimeout=120
Let me know if anything else is needed.