05-04-2012, 02:46 PM
Basic File Handling in PHP
Basic File Handling in PHP.docx (Size: 19.85 KB / Downloads: 27)
In this tutorial we intend to learn basic file handling mechanisn of PHP.
File handling functions in PHP are extremely usefull and userfriendly. Many websites use simple text files as there data store because it has following advantages
1) Minimization of cost. Cost of maintaining databases like Oracle are huge, thus files are low cost answer to these databases.
2) Taking back Up of your database is very easy. All you have to do is to copy the file.
3) It much easier to transfer a text file from one OS to another.
However there are divadvantages too
1) Text files do not support SQL Query languages. Thus you will have to code your data retrieval and updation algorithms yourself.
2) It does not use any indexing mechanism , thus searching mechanism is much slower.
3) You cannot use triggers, define primary keys , Foreign Keys etc.
MISC NOTES ABOUT FLOCK :
Flock() locks the file only after the file has been opened. So incase at instance A the file was opened and at instance A.5 the lock was obtained. Now the file contents are the contents that were present at instance A and not when the other program finished whatever (appending assumed). Hence fseek should always be used not only in appending but also when reading file contents.