|
|
|
ASP CGI And PHP Scripts And Record Locking What Every Webmaster Needs To Know
any of us install server-side (ASP, CGI or 1. Follow-up autoresponders PHP) scripts on our web typically store the list of sites, and many of this scripts subscribers to the autoresponder, store data on the server. as well where in the sequence of However, poorly designed scripts messages, each subscriber is. can experience performance Examples of autoresponder problems and sometimes even data scripts: corruption on busy (and not so http://www.scriptcavern.com/scr_e busy) web sites. mail_auto.php If you're not a programmer, why 2. Classified ad scripts store should this matter to you? (at least) a list of all the classified ads placed by Answer: Even if you're just visitors. Examples of this type installing and using server-side of script: scripts, you'll want to make sure http://www.scriptcavern.com/scr_c that the scripts that you choose lassified.php don't randomly break or corrupt your data. 3. Free for all links scripts store a list of all links posted First, some examples of the types by visitors. See some example of scripts which store data on scripts listed at: web servers include: http://www.scriptcavern.com/scr_f fa.php (Of course, many scripts in each of these (and other) categories 4. Top site scripts usually store are well-designed, and run a list of the members of the top perfectly well even on very busy site as well as information about web sites). the number of "votes" that each
has received. For examples of and does an update before the this type of script, see first copy of the script has http://www.scriptcavern.com/scr_t finished, a second copy of the opsite.php script starts running at the same time. So what kind of scripts have problems? And what sort of 3. There are a number of ways problems am I talking about? things can now go wrong, for example: Well the principle problems all relate to what happens when bits (a) What if the first copy of the of data from multiple users needs script reads in the data, then to be stored on updated at the the second copy reads the same same time. Some scripts handle data, then the first copy updates these situations well, but others the data, then the second copy don't... updates the data? Answer: any changes made by the first copy of DATA CORRUPTION the script can get lost. Here's a common data corruption (b) What if the first and second problem that can occur with many copy of scripts are both adding scripts: multiple bits of new data to the store at the same time? For 1. When some bit of data needs to example, imagine each needs to be updated, a copy of the store the headline, description server-side script starts and the name of the person running, and then starts updating posting a classified ad. Well, it. what can happen (with some scripts) is the two classified 2. If another user comes along ads can get intermingled, so you
might get (for example) solution by itself (in HEADLINE-1, DESCRIPTION-1, particular, a script which just HEADLINE-2, PERSON-1, does this could still have DESCRIPTION-2, PERSON-2. Or worse problems if multiple copies of a yet, you might get bits of each script update the same file at part of each classified ad, mixed the same time), but it does make with the bits of the other. This data corruption less likely, and type of thing is usually really if corruption does occur, at bad news, as your data may least it won't corrupt the entire consequently becoming unusable data store in one go. from that point on. 2. They can use file-locking. Does this sound too unlikely a This means that if one copy of a problem to worry about? Don't script is working with a file, bank on it... even if it happens another copy of the script is only 1 time in 1,000, or 1 in prevented from working on that 10,000, eventually it will file, until the first copy has happen: You need a solution. finished. File-locking works if done correctly, but programming So the real question is: is it it into a script needs to be done possible for programmers to very carefully and precisely, for create scripts without these every single possible case... kinds of problems? Fortunately even a tiny bug or omission can the answer is yes, and there are allow the possibility of a number of ways that programmers data-corruption in through the can address it: backdoor! 1. They can store each bit of 3. They can use a database (such data in a separate file. This as MySQL) to store the data. isn't necessarily a total Provided the data is properly
structured in the database, the (or all the links on your top database handles the locking site, or all the subscribers to automatically. And, as the your autoresponder, etc.). programmer doesn't have to write their own special locking What would happen? routines, the possibility of bugs and omissions are much reduced. Answer: Because each update can only be performed after the PERFORMANCE PROBLEMS previous update has been completely finished, your site Of course, avoiding having your may be slow, or even unable to data corrupted should be the handle all your users' requests. paramount consideration in choosing a script, but is there So what's the solution? anything else we need to be concerned about? There's two options that programmers can use: Answer: Performance 1. They can use lots of small Of course, all webmasters are files and file-lock each aiming to build busy high traffic individually (for example, one web sites... but will your per classified, one per top site scripts be able to handle the listing, etc.). Of course, this load? needs to be handled very carefully... Go back and re-read the paragraph on file-locking. Now think about 2. They can use a database (like what would happen if all the MySQL), as databases allow any classified ads on your classified one individual record ("row") to page were stored in a single file be updated, even when another is
also being updated. And one additional point: IN CONCLUSION 3. Even the best script is not Now, let's summarise: immune to hard-disk hardware failures, your web host being 1. Scripts that store data in struck by lightning, and all the files need to use file-locking to other snafus that can happen. So, avoid data-corruption, and they do take regular back-ups of any also need to break the data into data that you can't afford to separately updateable chunks to lose! avoid performance problems on busy web sites. In short, even if you're not a script programmer, you need to be 2. Scripts that store data in aware of data storage issues. In databases (like MySQL), provided future, when considering a script of course that they have been for your web site, don't be properly coded, are usually less afraid to ask some hard questions likely to suffer from about how it stores data and how data-corruption or performance well it handles multiple users. problems.
About the Author:
This article was written by Sunil Tanna of Answers 2000. For a
directory of ASP, CGI, PHP and Remotely hosted scripts, please
visit http://www.scriptcavern.com - and for scripts written by
Answers 2000 please visit http://www.scriptrocket.com
Read more articles by: Sunil Tanna
Article Source: www.iSnare.com
|
|