PHP - Atomicity

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
rohan.ckul
Forum Newbie
Posts: 2
Joined: Tue Mar 16, 2010 10:59 am

PHP - Atomicity

Post 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
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: PHP - Atomicity

Post 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.
M2tM
Forum Commoner
Posts: 41
Joined: Sat Feb 27, 2010 12:35 pm

Re: PHP - Atomicity

Post 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).
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP - Atomicity

Post by Weirdan »

Post Reply