php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14948 mssql_pconnect opens connection everytime is called
Submitted: 2002-01-09 09:44 UTC Modified: 2002-06-21 01:07 UTC
From: spilka at adash dot cz Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.1.1 OS: NT 4.0 SP5
Private report: No CVE-ID: None
 [2002-01-09 09:44 UTC] spilka at adash dot cz
Apache 1.3.22
Win NT SP5
PHP 4.1.1, run as DLL Apache module
MSDE SQL server
mod_mssql module loaded

Problem:
When opening connection to MSSQL database with mssql_pconnect, the connections are not persistently used. 
Instead, new connection is opened everytime. See MSSQL sp_who2 results:

SPID  Status      DBName Command          CPUTime DiskIO LastBatch      ProgramName    SPID  
----- ----------  ------ ---------------- ------- ------ -------------- -------------- ----- 
1     sleeping    master SIGNAL HANDLER   0       0      01/09 15:07:02                1    
2     BACKGROUND  UKOLY  LOCK MONITOR     0       0      01/09 15:07:02                2    
3     BACKGROUND  UKOLY  LAZY WRITER      0       0      01/09 15:07:02                3    
4     sleeping    UKOLY  LOG WRITER       0       0      01/09 15:07:02                4    
5     sleeping    UKOLY  CHECKPOINT SLEEP 0       0      01/09 15:07:02                5    
6     BACKGROUND  UKOLY  AWAITING COMMAND 0       5      01/09 15:07:02                6    
7     RUNNABLE    UKOLY  SELECT INTO      0       169    01/09 15:41:39 MS SQL Query   7    
8     sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:34 PHP 4.0        8    
9     sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:31 PHP 4.0        9    
10    sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:37 PHP 4.0        10   
11    sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:39 PHP 4.0        11   
12    sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:40 PHP 4.0        12   
13    sleeping    UKOLY  AWAITING COMMAND 0       0      01/09 15:41:41 PHP 4.0        13   

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-10 02:22 UTC] spilka at adash dot cz
Apache 1.3.22
Win NT SP5
PHP 4.1.1, run as DLL Apache module
MSDE SQL server
mod_mssql module loaded
The web server with PHP module and SQL server are running on the same machine.

Problem:
When opening connection to MSSQL database with mssql_pconnect, the
connections are not persistently used. 
Instead, new connection is opened everytime. MSSQL sp_who2
clearlz determines this (everytime REFRESH inbrowser is called new connection pops up).

Ondra.
 [2002-01-14 03:51 UTC] fjortiz at comunet dot es
I think this is not a bug, but Apache 1.3.x Win32 default behavior: if  you configured Apache to have 25 threads, for example, there will be 25 opened connections, because Apache seems to rotate requests among threads. So the persistent connection pool is PER THREAD, not per process.

IIS (and Apache 2 I think) uses a different way: it creates threads as they are needed. Pity this creates some thread-safe issues thanks to the clunky MSSQL DB-library...

And beware!, by default MSSQL DB-library only accepts 25 connections per process.
 [2002-01-14 04:41 UTC] spilka at adash dot cz
Hmm, it looks logically.
Unfortunaltelly, I still thing it's bug. 
To reach state of persistent connection you need f.e.25 requests, if the mechanism is as you tell.
But if you will measure time of openning connection, you will get f.e. 200ms first time and 5ms next time. So, the performance grows up as expected, but off to the resources.
But your SQL server need more resources for more connections and here you can get large lack of performance (as in my case).
And, documentation tells persistent connection is connection with the same server,uid and pwd.
 [2002-01-14 04:51 UTC] fjortiz at comunet dot es
The problem is Apache 1.3.x Win32, that creates 25 or 50 threads right away from the start. It's wiser the 'thread-on-demand' approach of IIS and Apache 2, because you spend only what you need.

You must think that Apache under most UNIX doesn't have threads, but processes, so a different connection pool is needed per process. Under Win32, Apache processes become threads, but PHP still has different data structures per thread. 

So considering it a bug is very subtle here, as it comes from a PHP architecture consideration. Maybe you want start a 'philosophical' discussion with the 'gurus'... 

of course, not me, not today!
 [2002-01-14 05:06 UTC] spilka at adash dot cz
I've checked PHP source.
It's as fjortiz@comunet.es said, hash table of connections is maintained per thread, so there is no persistent connection until reached count of thread pools.
----------------------------------------
I think one should update doc info, this is unwanted side effect behavior.
Correctly one must said use of the persistent effect discriminates Apache thread pool implementation.
-------------------------------------------
 [2002-06-20 12:52 UTC] sander@php.net
Not a bug in PHP. Each thread/child gets one connection.
 [2002-06-21 01:07 UTC] spilka at adash dot cz
Yes, right, each thread/child gets one connection.
But it's not a persistence, generally, each request gets it's own thread in the Apache, is it right?
It is not possible by design to maintain any type of persistence in the thread local storage in the NT Apache.
I think here is philosphical contradiction in the grasp of the persistence connection.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 05:01:26 2024 UTC