Paul Morrison wrote:
Hi,
On receiving input from a user I need to reference it to a text file to see
if that entry is present in the file. Is it possible to do this in php, or
will it need to be done in Javascript? Or is it not possible at all? Each
entry in the text file is on a new line if that makes any difference.
Cheers,
Paul
Using that method typically will not scale - especially if you are expecting new
entries in the file AND reading the file concurrently. You may want to consider
using a database (Oracle, SQLServer,MySQL).
There are various ways to do what you want, just remember, the larger the file
the longer it will take each "hit" to process (which is why you design a
database with proper indexing and a whole lot more)
read the entire file into an array and process through the array until 1) you
get to the end (no records found) or 2)you locate the requested record.
Depending on file size, this may be all you need.
you can use a system call to "grep" or "find" the requested entry - more
difficult to code, but can be faster if the file is very large.
When doing these sorts of things, just remember reading a 1MB file into an array
takes ~1MB+ of physical memory just for the one file. And depending on the
number of page hits, you could potentially be running a memory starved system
which equals poor performance - Use a database engine.
--
Michael Austin.
DBA Consultant
Donations welcomed.
Http://www.firstdbasource.com/donations.html
:)