Subject Webserver crash due to Ibase problems
Author Mikael Krogius
Hello all,

I am new on the list, and searched old messages but did not find
anything that would help. Am running a chat-service using Sambar 6.2,
PHP 5 and Firebird 2.0 alfa 3. Chat usernames, messages and statistics
(and a few other things) are stored in Firebird tables and read from
there to validate chatters and display messages etc. Each page reload
refreshes the chatters message screen (the chat is such that the
message-data can't be streamed).

For some unkown reason, firebird seems to stop responding or
alternatively PHP just can't handle the connections when traffic gets
"heavy". It all ends with a webserver crash, and sometimes (more
rarely), Firebird also crashes.

Examples of the errors in the PHP logfile:

Error:
PHP Warning: ibase_query() [function.ibase-query]:
Dynamic SQL Error SQL error code = -204 Table
unknown [TABLENAME] At line 1, column 21. in
N:\path\script.php on line 146

The PHP row contains:
$sth = ibase_query( $dbh2, $sql, $param1, $param2 );

Error:
PHP Warning: ibase_query() [function.ibase-query]:
internal gds software consistency check (can't continue
after bugcheck) in N:\path\script.php on line 855

The PHP row contains:
$sth1 = ibase_query( $dbh, $sql, + some Params );

And after a few hundred of the above, the log starts showing stuff
like this:
PHP Fatal error: Cannot redeclare ibblobtostr()
(previously declared in N:\path\other-script.php:18)
in N:\path\other-script.php on line 28

The chat does a lot of SELECT, UPDATE, DELETE and INSERT queries
depending on what the chatter does. At first, and sometimes for a few
hours all work just fine, but when there's over 150 simultaneous
chatters (ca. 3-6 connections to the DB per second) the problems seem
to begin.

I have tried everything it seems, but regardless if I open/close the
DB connection separately for each query or use one for the entire
pageload or commit after every change or commit only once per pageload
or use many DB connections or not, the problems are the same. I have
recreated the tables and moved Firebird to different servers and tried
many other things.

The scripts have a lot of logging but at the end of the day it seems
that the main problem is that Firebird stops responding correctly and
then everything just goes crazy and the webserver eats 500Mb of mem in
30 seconds and crashes. Just before the crash the PHP warnings and
errors get very strange but I believe the root of the problem must be
found and that will remove all the later errors that probably are
there just as something goes wrong first and threads/memory/something
leaks or does not get freed im memory etc... It often happens that it
takes 6 or more seconds to connect when the problems begin (I log the
time it takes to open the DB).

Currently both the webserver and Firebird are on the same server, and
even with heavy traffic they only eat ca 20% of CPU resources. I
wanted to test on Firebird 1.5, but could not find a tool that allows
me to import the tables from a 2.0 database.

You might wonder why it's under Sambar now - well, as it kept crashing
using Apache 2.0 I thought that maybe it's an Apache related problem
but that's not the case. For this kind of use Sambar is a LOT faster
then Apache anyway.

After days of googling and trying everything imaginable, I need help.
Has anyone experienced this? Any suggestion as to what I could change
to handle the "heavy" loads better? Anything I might overlook
regarding freeing DB connections and freeing results? (I free all
ibase_query() results that can be freed with ibase_free_result()).

Even ridiculous ideas and suggestions are very welcome!

- Mikael