From:             fjortiz at comunet dot es
Operating system: Win2K Server
PHP version:      5.0.4
PHP Bug Type:     Apache2 related
Bug description:  PHP5+OLEDB(COM)+IIS pools DB connections, 
PHP5+OLEDB(COM)+Apache2 does not!

Description:
------------
Ok, this seems a tricky one, so sorry for the long post. It's related to
the way Apache2 and IIS work with COM objects. So maybe some combined
Apache2/IIS/Database/COM skills are needed.

I want to connect to a DB (MSSQL in this case), but I need some features
unavailable under php_mssql (asked to F. Kromman, thanks). So I'm forced
to use COM/OLEDB via ADODB.Connection. COM works great now under PHP5
but...

I have this problem: 

If I use this combination:
PHP5+OLEDB(COM)+IIS: IIS keeps a pool of persistent connections so the
next PHP scripts re-use this open connection and doesn't have to open a
new one.

PHP5+OLEDB(COM)+Apache2: Apache2 works fine with the queries but at the
end of my PHP script, the connection is closed, and every subsecuent PHP
script has to open a new connection.

It's not a critical issue as long as your DB server is on the same machine
as the Web Server:

Open new connection on Apache2: 0.02 secs.
Re-use existing connection on IIS: 0.002 secs.

But it does matter if both are on different machines and/or while on very
heavy traffic web-sites.

My theory: not a COM guru, but maybe Apache2 lacks being compiled with
some COM Apartment threading model which IIS already has. I'm really sad
about being impelled to work with this COM/OLEDB shit but I'd really like
to get this working on PHP5+Apache2 (will have to swap to PHP5+IIS if
there is no way to solve this).

Thanks in advance


Reproduce code:
---------------
<?
// Win32, need MDAC and a SQL Server
$HOST = "your-sql-server";
$USER = "user";
$PASS = "pwd";
$DB = "database";

$dsn = "Provider=SQLOLEDB;Data Source=$HOST;User
Id=$USER;Password=$PASS;Initial Catalog=$DB";
$charPage = CP_UTF8;

$db = new COM("ADODB.Connection", NULL, $charPage);
$db->Open($dsn);

// sample query to get all the SQL Server processes for your Database,
along with the App that created them
// (Apache, IIS, others...)
$query="select distinct sd.name, sp.program_name from master..sysprocesses
sp
        inner join master..sysdatabases sd on sd.dbid=sp.dbid 
        where sd.name='$DB'
        order by 1,2";

$rs = $db->Execute($query);

// some output
print "<table border=1>";
while (!$rs->EOF)       {
        print
"<tr><td>".$rs->Fields["program_name"]->Value."</td><td>".$rs->Fields["name"]->Value."</td></tr>\n";
        $rs->MoveNext();
}
print "</table>";
$db->Close();  // doesn't really matter, IIS keeps connection open,
Apache2 closes it even if this line is commented

?>

Expected result:
----------------
We list all the SQL Server open processes, during and after PHP script
execution:

select distinct sd.name, sp.program_name from master..sysprocesses sp
        inner join master..sysdatabases sd on sd.dbid=sp.dbid 
        where sd.name='nc208'
        order by 1,2

While executing PHP5+Apache2:
database        Apache HTTP Server
database        SQL Query Analyzer                                              
 
                                                              
database        SQL Query Analyzer - Object Browser                             
 
                                                              

When PHP script ends:
database        SQL Query Analyzer                                              
 
                                                              
database        SQL Query Analyzer - Object Browser                             
 
                                                              

PHP5+Apache2 CLOSES CONNECTION --> not there when script finishes.

While executing the same on PHP5+IIS:
database        Internet Information Services
database        SQL Query Analyzer                                              
 
                                                              
database        SQL Query Analyzer - Object Browser                             
 
                                                              

When PHP script ends:
database        Internet Information Services
database        SQL Query Analyzer                                              
 
                                                              
database        SQL Query Analyzer - Object Browser                             
 
                                                              

PHP5+IIS KEEPS CONNECTION OPEN for re-use --> at least for 60 seconds,
which is a default OLEDB driver setting I think.




-- 
Edit bug report at http://bugs.php.net/?id=33681&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33681&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33681&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33681&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33681&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33681&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33681&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33681&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33681&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33681&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33681&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33681&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33681&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33681&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33681&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33681&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33681&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33681&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33681&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33681&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33681&r=mysqlcfg

Reply via email to