My Portfolio About Me Cert's and .edu'sContact MeMy Security Blog
Online Tools
Online QBASIC Compiler
World Timezones
PHP Articles
Auto Theme Changer
Article System
Filtering Input in PHP fopen for Databases?
Visual Basic Articles
Unix Timestamp VB6
Other Articles
Linux vs. Windows
Compare Browsers
PDF My PDFs
Web Security with PHP
E-Mail Security
Offsite Articles
WAMP Server PHP File Functions Securing GET Requests Homebrew Server
FOpen for Databases

FOPEN for Databases?


This "Claptrap" assumes that you have some prior knowledge of databases, PHP, or other programming languages. However, for those that don't, I'll try to sum it up in a way for visitors to understand.

The statement "fopen", or as PHP would like me to call it "fopen()", is PHP's File Open command. With this file you can read, write, and append to files -- a wonderful feature. In my programming past, I never had a single issue with my applications using similar functions (OPEN in BASIC, for example). I used them for creating a file-name cache system, searching records, storing information, etc.

Then came the true test -- An online message board that allowed multiple people to access my databases at one time. Because of my single-threaded past, I never suspected the issues that FastCGI (which is a multi-threaded application that runs several instances at one time) would present.

As two users were posting to a topic at one time (or even multiple topics at one time), the server became haywire trying to sort out the multiple file reads of the same file, which opened, inserted data, and sorted the results; finally saving it.

For those who have developed single-user at-a-time applications, you may not know what a "Race Hazard" is.

For an elementary explanation: Imagine two children drawing on the same one-inch sheet of paper, each with large markers. Eventually they will bump hands, distorting what their original intention was.

Well, because PHP (particularly PHP using the FastCGI interface) will open several processes, each capable of operating independently (and unaware of each other), it is similar to having two children writing in the same box. An easy way to fix this for Linix servers would be setting a locking flag, but for Windows users, it isn't so easy.

You now have an index, or collection of files (please tell me they're not part of a life-support system), that has all kinds of arbitrary data strewed about inside of it. The script that reads this file cannot make any logical sense of what is going on, because your system of using line-feeds for field delinaetion was a failed approach, and the dates are appearing in the post field, the post is the username, and the date isn't showing because it isn't a numeric variable, so the DATE() function can't make any sense of it.

So how can fopen be used for databasing? Well, first things first, I find that learning MySQL is higly beneficial, as the cache improves speed, the row-locking eliminates the race hazard, and one-file backups for a site? Well...I don't think I need to say more.

Can it be done? Yes, it sure can. But, as I've painfully learned: Why re-invent the wheel?
Name:
Posted: Thursday, July 9, 2009 at 12:34:24 AM
By: teh1337
Cool story broseph.

God ur god
Posted: Sunday, October 25, 2009 at 12:50:03 PM
By: Bob Lerner
Figures I'd get a few spam posts...Less than I'd have initially thought, but some nonetheless...
Posted: Sunday, November 8, 2009 at 7:54:29 AM
By: Pharmb340
Very nice site!
Posted: Wednesday, December 9, 2009 at 1:19:33 AM
By: alexk189
Very nice site! a href"http:aieypxo.comtoxats1.html"is it yours tooa
Posted: Wednesday, December 9, 2009 at 1:19:34 AM
By: alexe947
Very nice site! urlhttp:aieypxo.comtoxats2.htmlis it yours toourl
Posted: Wednesday, December 9, 2009 at 6:54:01 AM
By: uhurtrlmm
nPKtrR a href"http:nfnmaamoxhyu.com"nfnmaamoxhyua, urlhttp:jqrhmeibcyms.comjqrhmeibcymsurl, linkhttp:glofkyyptkpb.comglofkyyptkpblink, http:tloflcxbjlgy.com
Posted: Thursday, December 17, 2009 at 1:07:46 PM
By: alexc744
Very nice site! a href"http:yieopxa.comyxyrxtx1.html"is it yours tooa
Posted: Thursday, December 17, 2009 at 1:07:46 PM
By: alexc877
Very nice site! urlhttp:yieopxa.comyxyrxtx2.htmlis it yours toourl
Posted: Monday, December 21, 2009 at 4:00:32 AM
By: PgufKSJs
IIvh3I a href"http:nscywfppekse.com"nscywfppeksea, urlhttp:tctreewklwfp.comtctreewklwfpurl, linkhttp:fakedxwfnfte.comfakedxwfnftelink, http:shcoebhtdatx.com
Posted: Tuesday, December 22, 2009 at 11:20:00 AM
By: alexa845
Very nice site! a href"http:ypxaieo.comrrqasoo1.html"is it yours tooa
Posted: Tuesday, December 22, 2009 at 11:20:00 AM
By: alexd126
Very nice site! urlhttp:ypxaieo.comrrqasoo2.htmlis it yours toourl
Posted: Sunday, December 27, 2009 at 12:41:44 AM
By: alexe118
Very nice site! a href"http:opeyixa.comqvoxvya1.html"is it yours tooa
Posted: Sunday, December 27, 2009 at 12:41:45 AM
By: alexb663
Very nice site! urlhttp:opeyixa.comqvoxvya2.htmlis it yours toourl
Posted: Tuesday, December 29, 2009 at 4:43:55 PM
By: Pharmd745
Very nice site! a href"http:ypxoiea.comovyrakv1.html"cheap viagraa
Posted: Tuesday, December 29, 2009 at 4:43:58 PM
By: Pharme364
Very nice site! urlhttp:ypxoiea.comovyrakv2.htmlcheap cialisurl
Posted: Tuesday, December 29, 2009 at 4:46:03 PM
By: Pharme818
Very nice site! cheap cialis http:ypxoiea.comovyrakv4.html
Posted: Tuesday, December 29, 2009 at 4:46:06 PM
By: Pharmb136
Very nice site!
Posted: Wednesday, December 30, 2009 at 5:05:17 AM
By: alexa48
Very nice site! a href"http:apxoiey.comqoxvyt1.html"is it yours tooa
Posted: Wednesday, December 30, 2009 at 5:05:17 AM
By: alexd538
Very nice site! urlhttp:apxoiey.comqoxvyt2.htmlis it yours toourl
Posted: Friday, January 1, 2010 at 3:48:17 AM
By: Pharmb506
Very nice site! a href"http:oieypxa.comkyrayk1.html"cheap viagraa
Posted: Friday, January 1, 2010 at 3:48:22 AM
By: Pharmf396
Very nice site! urlhttp:oieypxa.comkyrayk2.htmlcheap cialisurl
Posted: Friday, January 1, 2010 at 3:48:35 AM
By: Pharmg573
Very nice site! cheap cialis http:oieypxa.comkyrayk4.html
Posted: Friday, January 1, 2010 at 3:48:42 AM
By: Pharmd231
Very nice site!
Posted: Monday, January 11, 2010 at 3:21:01 PM
By: alexb84
Very nice site! a href"http:ypxaieo.comoooxvqy1.html"is it yours tooa
Posted: Monday, January 11, 2010 at 3:21:02 PM
By: alexf898
Very nice site! urlhttp:ypxaieo.comoooxvqy2.htmlis it yours toourl
Posted: Saturday, January 23, 2010 at 6:42:15 AM
By: DLDdwoPbzJQwiKf
4QDszO a href"http:rqqfaahgcawy.com"rqqfaahgcawya, urlhttp:mkjcwywwnlqg.commkjcwywwnlqgurl, linkhttp:kygmftutmcsn.comkygmftutmcsnlink, http:eawnhlwfurwp.com
Posted: Thursday, January 28, 2010 at 9:46:28 AM
By: npznismmn
ccDRLq a href"http:dfxaislhhvxq.com"dfxaislhhvxqa, urlhttp:qlwbdahbtcdw.comqlwbdahbtcdwurl, linkhttp:iqippyxtyrzv.comiqippyxtyrzvlink, http:etibmjztlycg.com