Subject | Re: [firebird-php] First Steps and Transaction Handling |
---|---|
Author | masotti |
Post date | 2009-04-30T11:28:03Z |
Hello Matthias,
maybe someone answer before me, with better knowledge and writing speed.
Matthias Hanft ha scritto:
between PHP app and server.
Nothing to have with transactions.
PHP ibase_* docs states that transactions are committed or rolled back
at the end of the script.
First problem: web server caching. I'm not sure that web servers (i.e.
Apache) really releases resources.
Check who is allready connect to your server to verify which
transaction aren't committed yet.
I noted same behavihour, and restarting Apache cleaned all problems (no
data lost).
opened before by the PHP ibase client library.
Transactions are rolled back at end of PHP script. You must use
ibase_commit() on default transaction to commit.
Autocommit isn't an option, AFAIR.
$trans are optional.
Both are mandatory when you are working on more than one database
because system is unable to detect a "default" for your query.
There is a ibase_trans() overload with more than one resource link
parameter, when you need a transaction on more that one db to perform a
two phase commit.
READ_ONLY connections so this can be rolled back safely every time you
use it.
script (loading another page) you need to reconnect and that is a time
consuming activity. Pool speeds up things.
is quite regular.
officially "closed" by scripts.
My web database are now:
Oldest transaction 198406
Oldest active 198407
Oldest snapshot 198407
Next transaction 198408
and
Oldest transaction 12498
Oldest active 12499
Oldest snapshot 12499
Next transaction 12500
after navigating a while, becomes
Oldest transaction 12562
Oldest active 12563
Oldest snapshot 12563
Next transaction 12564
Ciao.
Mimmo.
maybe someone answer before me, with better knowledge and writing speed.
Matthias Hanft ha scritto:
> In the support mailing list, I was told that PHP uses connectionConnections pooling try to semplify and speed up connection timings
> pooling (can I switch that off? "ibase.allow_persistent = Off"
> seems not to be the setting for it), but why do connections have
> something to do with transactions?
>
between PHP app and server.
Nothing to have with transactions.
PHP ibase_* docs states that transactions are committed or rolled back
at the end of the script.
First problem: web server caching. I'm not sure that web servers (i.e.
Apache) really releases resources.
Check who is allready connect to your server to verify which
transaction aren't committed yet.
I noted same behavihour, and restarting Apache cleaned all problems (no
data lost).
> In this respect, I just don't quite understand the mapping betweenWith ibase_pconnect() you can reuse same connection if it was allready
> PHP and FB transactions fully. (I do with Delphi.) Currently, in
> PHO, I'm using
>
> $dbhandle = ibase_connect("host:database", "user", "pass", "latin1", 0, 3);
> // does opening a database cause the creation
> // of some "implicit" or "default" transaction?
>
opened before by the PHP ibase client library.
Transactions are rolled back at end of PHP script. You must use
ibase_commit() on default transaction to commit.
Autocommit isn't an option, AFAIR.
> $stmt = "select ID, MODEL from ACCOUNTS where...";Yes: I use it only for INSERT / UPDATE / DELETE to be sure to commit ASAP.
> $trans = ibase_trans( IBASE_DEFAULT, $dbhandle );
> // no explicit need for ibase_trans? ibase_query seems
> // to work without transaction, too
>
> $sth = ibase_query($dbhandle, $stmt);There are many overloading of this functions, and AFAIR $dbhandle and
> // some sources tell me to use "$trans" instead of "$dbhandle"
> // here, but this does _not_ adjust the transaction counters
> // in "gstat -h"!
>
$trans are optional.
Both are mandatory when you are working on more than one database
because system is unable to detect a "default" for your query.
There is a ibase_trans() overload with more than one resource link
parameter, when you need a transaction on more that one db to perform a
two phase commit.
> $row = ibase_fetch_object($sth));For SELECT only transaction (without updating of data) you can prepare a
> $myresult["ID"]=$row->ID;
> $myresult["MODEL"]=$row->MODEL;
> ibase_free_result($sth);
>
> ibase_commit($trans);
> // any need for committing any "implicit" transaction here?
> // ibase_commit(); and/or ibase_commit($dbhandle); ?
>
READ_ONLY connections so this can be rolled back safely every time you
use it.
> ibase_close($dbhandle);Connections aren't needed to be closed, or every time you restart a
> // really closed now? or just put back into some pool?
>
script (loading another page) you need to reconnect and that is a time
consuming activity. Pool speeds up things.
> Is the above code generally correct?I'd not close connections, but use only pconnect(), but remaining code
>
is quite regular.
> I'd really *love* to see the "gstat -h" transaction countersTry to verify if your server keeps alive transactions that are instead
> always "clean" (Oldest=X, X+1, X+1, Next=X+2) after each PHP
> access (as I do after each Delphi access) - is this possible
> at all?
>
>
officially "closed" by scripts.
My web database are now:
Oldest transaction 198406
Oldest active 198407
Oldest snapshot 198407
Next transaction 198408
and
Oldest transaction 12498
Oldest active 12499
Oldest snapshot 12499
Next transaction 12500
after navigating a while, becomes
Oldest transaction 12562
Oldest active 12563
Oldest snapshot 12563
Next transaction 12564
Ciao.
Mimmo.