Re: [PHP-DB] transactions and persitent connections
At 12:52 +0900 9/1/02, Jean-Christian Imbeault wrote: Paul Dubois wrote: I am worried that if I use persistent connections it might be possible for more than one PHP script to be inside the same transaction at the same time. Not at the *same* time, because although a persistent connect might be used by more than one script, this will be serially rather than simultaneously. That does mean it's possible for a transaction to be started by one script and then either committed or rolled back by the next if they share a connection. That's exactly what I meant and feared. In a sense User 2 who is re-using User 1's connection would be in User 1's un-completed transaction. And the result of User 2's transaction (commit or rollback) would affect the first transaction. Yuck ... 2- If user 1's hits the stop button on his browser, what happens to his transaction? I assume it is stopped. But what about the connection? If user 2 No, the script won't have any idea the stop button has been pressed. It should have executed and completed its transaction regardless of what the user does. Really? I don't exactly know how PHP script execute but I though that is that the user goes to a page that starts a script and then closes the browser that causes the script to end prematurely. The script doesn't know anything about what the browser does. Am I wrong? Yes. Does the script go from start to finish even though the connection to the browser has been severed. I.e. The script will run complete even if there is output to the browser as the script is running? Not necessarily. It won't base its actions on what the browser might happen to be doing while it's running, but it might exit early because of a bug, for example. But normally it will run to completion. If the script goes from start to finish regardless of what the user does that would be nice. That way I am sure a transaction will go from start to finish, and if I make sure to either commit or rollback the transaction at the end of the script then I don't have to worry. You should write your script so that is *does* go from start to finish. Forget about what the user might be doing. Maybe the safest thing to do is not use persistent connections at all? Or in your opinion is there a safe way to use persistent connections and transactions? No. Don't use persistent connections. If some unforeseen problem does occur with your script, the connection may be left open and you'll have the problems you're concerned about. If you use a non-persistent connection and a problem occurs, the connection will be closed (which presumably will make your transaction roll back). Jc PS Great book! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] transactions and persitent connections
Paul Dubois wrote: Does the script go from start to finish even though the connection to the browser has been severed. I.e. The script will run complete even if there is output to the browser as the script is running? Not necessarily. It won't base its actions on what the browser might happen to be doing while it's running, but it might exit early because of a bug, for example. But normally it will run to completion. Thanks for clearing that up for me. You should write your script so that is *does* go from start to finish. Forget about what the user might be doing. Trying *very* hard. No. Don't use persistent connections. If some unforeseen problem does occur with your script, the connection may be left open and you'll have the problems you're concerned about. If you use a non-persistent connection and a problem occurs, the connection will be closed (which presumably will make your transaction roll back). Thanks. With what you've explained I understand the pitfalls persistent connections might and will not be using them. Such a shame ... Thanks again for all the information! Jc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] transactions and persitent connections
I'm a little confused/worried about database transactions, persistent connections and PHP. I am worried that if I use persistent connections it might be possible for more than one PHP script to be inside the same transaction at the same time. For example: 1- page1.php is a script that opens a persistent connection to a DB and starts a transaction. 2- User 1 goes to page1.php 3- User 2 goes to page1.php My questions: 1- is it possible that user 2 will be using the same connection as user 1? So if user 1's transaction fails so will user 2's? 2- If user 1's hits the stop button on his browser, what happens to his transaction? I assume it is stopped. But what about the connection? If user 2 gets the same connection, will his transaction fail? Thanks, Jc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] transactions and persitent connections
At 17:46 +0900 8/31/02, Jean-Christian Imbeault wrote: I'm a little confused/worried about database transactions, persistent connections and PHP. I am worried that if I use persistent connections it might be possible for more than one PHP script to be inside the same transaction at the same time. Not at the *same* time, because although a persistent connect might be used by more than one script, this will be serially rather than simultaneously. That does mean it's possible for a transaction to be started by one script and then either committed or rolled back by the next if they share a connection. This can happen if the first script fails to issue a COMMIT or ROLLBACK, perhaps by exiting early due to an error. If the second script comes along and commits or rolls back, that affects the queries issued by the first script. For example: 1- page1.php is a script that opens a persistent connection to a DB and starts a transaction. 2- User 1 goes to page1.php 3- User 2 goes to page1.php My questions: 1- is it possible that user 2 will be using the same connection as user 1? So if user 1's transaction fails so will user 2's? 2- If user 1's hits the stop button on his browser, what happens to his transaction? I assume it is stopped. But what about the connection? If user 2 No, the script won't have any idea the stop button has been pressed. It should have executed and completed its transaction regardless of what the user does. Perhaps you are thinking that user 1 visits the page and begins a transaction, and then visits it again to complete the transaction? That doesn't work. You have no guarantee that user 1 will get the same connection both times. (That is, don't try to spread a transaction out over multiple visits by a user.) gets the same connection, will his transaction fail? Thanks, Jc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] transactions and persitent connections
Paul Dubois wrote: I am worried that if I use persistent connections it might be possible for more than one PHP script to be inside the same transaction at the same time. Not at the *same* time, because although a persistent connect might be used by more than one script, this will be serially rather than simultaneously. That does mean it's possible for a transaction to be started by one script and then either committed or rolled back by the next if they share a connection. That's exactly what I meant and feared. In a sense User 2 who is re-using User 1's connection would be in User 1's un-completed transaction. And the result of User 2's transaction (commit or rollback) would affect the first transaction. Yuck ... 2- If user 1's hits the stop button on his browser, what happens to his transaction? I assume it is stopped. But what about the connection? If user 2 No, the script won't have any idea the stop button has been pressed. It should have executed and completed its transaction regardless of what the user does. Really? I don't exactly know how PHP script execute but I though that is that the user goes to a page that starts a script and then closes the browser that causes the script to end prematurely. Am I wrong? Does the script go from start to finish even though the connection to the browser has been severed. I.e. The script will run complete even if there is output to the browser as the script is running? If the script goes from start to finish regardless of what the user does that would be nice. That way I am sure a transaction will go from start to finish, and if I make sure to either commit or rollback the transaction at the end of the script then I don't have to worry. Maybe the safest thing to do is not use persistent connections at all? Or in your opinion is there a safe way to use persistent connections and transactions? Jc PS Great book! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php