Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Cornald Kruyt
November 25, 2005, 1:29 pm
rate this thread
I've an database import script written in PHP which used ADO via COM.
It makes thousands of queries to a MS-SQL server. The problem is that
the process runs out of sockets.
The MSSQL server is used in the following way:
// In the beginning of the script, the connection is set up
Library=DBMSSOCN;Data Source=FOO;Database=BAR;User ID=FOO;Password=BAR";
// Typical query
$rs=$dbc->execute("SELECT ... FROM ...");
// process the result set here
// Close and free the resultset object:
The script executes many queries in rapid succession. When I inspect
the output of 'netstat -an' during execution, I see thousands of open
TCP 192.168.1.210:3960 192.168.1.13:1433 TIME_WAIT
TCP 192.168.1.210:3961 192.168.1.13:1433 TIME_WAIT
TCP 192.168.1.210:3964 192.168.1.13:1433 TIME_WAIT
Sometimes the script even dies with a COM exception error, that it can't
make a connection to the MSSQL server anymore. This happens when +/-
4000 sockets are in the TIME_WAIT state. After two minutes these
sockets are automatically closed by Windows and MSSQL connections are
Is this a known problem? I couldn't find it in Google.
is there a way to make ADO (or PHP) reuse the existing socket, instead
of opening a new one for each Execute?
Re: Excessive socket usage using MS-SQL server via ADO COMobject
I am not using the ADOdb library, but thanks for the tip anyway: I will
look into the source code of ADOdb to see how PConnect() is implemented.
Maybe that will give some insight.
What do they mean by 'persistent connection'? That the connection is
kept alive between script invocations? Or that multiple queries done
from the same script invocation reuse the existing MSSQL socket?