Page 1 of 1

PHP - Atomicity

Posted: Mon Mar 29, 2010 11:16 am
by rohan.ckul
Hi

I am new to PHP based server side scripting; so this might seem a very strange question.

A typical page on my website will consist of some php based scripting embedded in html tags. Now suppose someone clicks to go to this page, and suddenly the connection breaks, because of either this user pressing the stop button or internet disconnection etc. Then, which of the following three outcomes will ALWAYS result ?

a) The entire PHP code gets executed on the server, since the request has already reached the server, and php is really a server side scripting language. But this also means that unknown to the user, this code might have executed, and this might not be a good thing in scenarios whether suppose user was registering with a website, but does not know whether the registration has completed.

b) Since connection broke, the PHP code does not get executed at all.

c) Some part of the PHP code gets executed, depending upon when the connection broke. (Really undesirable, I suppose)

I tend to believe that (a) is the scenario that will ALWAYS TAKE PLACE, since I believe that might be the advantage of server side scripting.

Any comments ?

TIA

Re: PHP - Atomicity

Posted: Mon Mar 29, 2010 11:27 am
by omniuni
Well, really this depends on how you construct your code. If you wanted to, I suppose you could add some checks to see if the computer that sent the page is responding before processing the data, but otherwise, I believe the script simply executes with what information it has. The best idea is to try to make sure that pages load quickly, and that you check the integrity of data before you make changes.

Re: PHP - Atomicity

Posted: Tue Mar 30, 2010 3:37 am
by M2tM
I'm not sure what you are getting at, a) is basically right. This is why "double posting" is a relatively common term on forums. Some forum software can detect double posting by checking the contents of the previous message the user posted and seeing if it matches identically, but most do not. With user registration typically this is not a concern as confirmation e-mails are sent out (usually, but it depends on the script) and also because when signing up for an account the most logical thing is to make sure no such duplicate name exists and so if the user were unaware the script completed they would likely get an e-mail and also a message when trying again saying "that username is taken" etc.

In practice this is not the huge problem that it appears to be in -most- situations, but it is something you want to consider when designing the control flow of things. Programming to support the "back button" and "abandoning the page mid-step in a multi-step process" is very tough, but luckily for most non-critical systems it is not a serious problem because the data is not mission-critical and mistakes can be solved when they do crop up via admin intervention (such as double-posts, or incomplete user account details).

Re: PHP - Atomicity

Posted: Tue Mar 30, 2010 3:46 am
by Weirdan