Hi,
I use Postgresql 7.2.2 + php 4.2.3 and I meet a problem with
transaction and connections interruption.
The application is the famous example of the bank accounts and the money
transfers. I consider a table named "DEAL" where each transaction is
saved. Each tuple has an id number as key. When a tuple is added,
the maximum value of id is computed, and increased by one to
determinate the key of the next tuple.
My script php follows this steps :
ignore_user_abort(0|1)
Compute the key -> v
BEGIN WORK
UPDATE the first bank account with v (credit)
sleep(300)
UPDATE the second bank account with v+1 (debit)
COMMIT WORK
While the sleep, the client may use the STOP button on his browser and
stop the connection.
I tried to execute exhaustive tests : ignore_user_abort(0) or
ignore_user_abort(1), with or without transaction, with or
without rollback.
For these tests, I follow two steps :
1/ the client execute the first request but stops the connection
while the sleep instruction.
2/ with pgaccess, I read the content of DEAL
3/ the client executes a new request without interruption
4/ the result is displayed on the browser and checked with pgaccess
--------------------
TEST 1
--------------------
request 1
*********
ignore_user_abort(0)
Compute the key -> v=10
BEGIN WORK
UPDATE the first bank account with v as key (credit)
sleep(300) ------> INTERRUPT !!!!
UPDATE the second bank account with v+1 as key (debit)
COMMIT WORK
Result : nothing new in the database (with pgaccess)
request 2
*********
ignore_user_abort(0)
Compute the key -> v=10
BEGIN WORK
UPDATE the first bank account with v (credit)
UPDATE the second bank account with v+1 (debit)
COMMIT WORK
Result : the request 1 is executed now ! and while the key
(v=10) is the same, the request 2 fails.
Problem : why the whole first request is taking into account
now ?
--------------------
TEST 2
--------------------
The same by removing BEGIN and COMMIT.
The first request : only the first update (before the stop)
is executed
The second request is executed correctly.
Problem : ignore_user_abort is called with 0, so why the execution
of the script for the first request doesn't continue ?
--------------------
TEST 3 and 4
--------------------
The tests 3 and 4 reproduce the test 1 and 2 by using
ignore_user_abort(1).
The results are absolutely the same !
--------------------
TEST 5 and 6
--------------------
The tests 5 and 6 reproduce the test 1 and 2 by using ROLLBACK
if ( connection_aborted() ) { ROLLBACK WORK; exit } is added
after the sleep.
The results are absolutely the same again !
I find the results very strange, isn't it.
In advance, thanks for your help.
mb
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php