All
We have a system running Windows Server 2016 with IIS 10 and PHP 7.1.16. The scripts connect to a SQL Server database through ODBC. It works very well during normal conditions, however we get a surge every Friday as people try to get things done before the weekend. Every now and again connections to the database begin to fail, but continuing to try will eventually get you through.
My Db connection script is as follows (the function allows me to easily make new connections on the fly if I need to, since SQL Server requires prior statements to be closed before new queries can be submitted):
<?php
include "config.inc.php";
function DBConnFactory()
{
return new PDO($dsn='odbc:Driver={SQL Server};Server='.DB_INST.';Database='.DB_DATABASE.';APP=WhatsMyAppAgain;Trusted_Connection='.DB_TRUST);
}
try
{
$db=DBConnFactory();
}
catch (Exception $e)
{
error_log($e->getMessage().' in '.$e->getFile().', on line '.$e->getLine());
die('Can\'t connect to the database!');
}
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// leave the ending tag off, otherwise you could get
// random whitespace that could block header changes.
When it begins to fail, I get the following message in the logs:
[19-Oct-2018 17:38:42 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:38:43 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:39:10 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:44:28 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:45:13 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:46:15 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
[19-Oct-2018 17:48:25 Australia/Sydney] SQLSTATE[] SQLDriverConnect: 0 in C:\inetpub\wwwroot\WhatsMyAppAgain\LIVE\dbconn.inc.php, on line 7
There's no errors in the Event Viewer that provide any clues as to what's going on. I know it isn't the SQL server because my development environment connects to the same SQL server and I do not see the issue there, and when the issue affects the LIVE environment, the QA environment (which is on the same server) is affected as well.
I've created stub scripts that create any number of connections through the same ODBC, but even when I create 3,000 connections (far beyond what the site would create even if everyone tried to jump on at once), I cannot reproduce this.