Reload page in the middle of a transaction

If the user stops loading the page entirely in the middle of a transaction and then refreshes the page, will the transaction be applied twice?

+3


source to share


1 answer


The short answer is you should check. Transactions are completed if even one request fails. The real problem here, however, is that if the user aborts the download, that doesn't mean the server will stop executing code. Canceling the page load means that the user has decided not to receive data back. Your web server doesn't have to obey, and neither does PHP - they may not even know that the user has closed the pipe at their end. We are now introducing a completely different play area - PHP can be embedded in servers or it can act as a standalone server (known asphp-fpm

). If PHP is embedded in a server like Apache via mod_php, Apache decides whether it will interrupt the thread or process that is running the PHP process. He can still decide to do it all, collect the result, and then try to write the result back to the socket - only to realize that the user is no longer there.

As you can see, the complexity of your problem is not as simple as "what if the user interrupts" - it is not up to the user to control the execution of the program on your web server.



Now suppose the web server is ready to play ball and that it somehow tells PHP to stop executing - in this case the transaction will not be executed, it will not be executed because the commit will not be released.

If the server doesn't want to play ball or just doesn't have the ability to interrupt the PHP process - then yes, you will end up with two or more transactions executed, depending on what your users are doing.

+5


source







All Articles