On my new brand AWS server I have a big problem with PHP and Firebird DB.
Current configuration:
- Debian 10 (buster)
- PHP 7.3.11-1~deb10u1 (cli) (built: Oct 26 2019 14:14:18) ( NTS )
- LI-V3.0.5.3310 Firebird 3.0 Super
This is not real code from my application, but after a days I think this is the problem:
$dbh = ibase_connect('localhost:/*****/temp.fdb', 'SYSDBA', '*****');
$stmt = 'SELECT field_id FROM A0000';
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
$stmt0 = "SELECT * FROM A0000 WHERE field_id=?";
$pstm0 = ibase_prepare($dbh, $stmt0);
$sth0 = ibase_execute($pstm0, $row->field_id);
$row0 = ibase_fetch_object($sth0);
echo $row0->field_id . "\n";
ibase_free_query($pstm0);
ibase_free_result($sth0);
$sth0 = null;
$pstm0 = null;
}
ibase_free_result($sth);
ibase_close($dbh);
Obviously the ibase_prepare goes outside the loop for real performance.
This simple code makes Firebird goes in error with "too many open handles to database" (around the 64000th iterations, and Firebird with 16GB of RAM.
The same code on our old server (PHP 5.3/Firebird 2.5) works fine.
With this code instead all works perfectly (even on new server):
$dbh = ibase_connect('localhost:/*****/temp.fdb', 'SYSDBA', '*****');
$stmt = 'SELECT field_id FROM A0000';
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
$stmt0 = "SELECT * FROM A0000 WHERE field_id=?";
$sth0 = ibase_query($dbh, $stmt0, $row->field_id);
$row0 = ibase_fetch_object($sth0);
echo $row0->field_id . "\n";
ibase_free_result($sth0);
$sth0 = null;
}
ibase_free_result($sth);
ibase_close($dbh);
Seems the proble was the ibase_prepare that is never released.
Is my code at fault?