Re: Referencing a txt file



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
:)
.



Relevant Pages

  • Re: Need Help deleting record from text file
    ... Entering data into a database will be a bit slower as it indexes the data on ... whole array into memory. ... data entry & retrieval and a bit of simple SQL. ... I certainly wouldn't suggest building huge strings or using ListBoxes ...
    (microsoft.public.vb.general.discussion)
  • Re: File Removal after Database Comparison
    ... images haven't been removed and as such, short of removing all images, ... if file is not in the database { ... I have the list of files in the directory in an array. ... I know that I need to go through the array and check to see if an entry with the same recordid exists, but I'm not sure how to get the recordid from the filenames. ...
    (comp.lang.php)
  • Re: File Removal after Database Comparison
    ... images haven't been removed and as such, short of removing all images, ... if file is not in the database { ... I have the list of files in the directory in an array. ... I know that I need to go through the array and check to see if an entry with the same recordid exists, but I'm not sure how to get the recordid from the filenames. ...
    (comp.lang.php)
  • Re: File Removal after Database Comparison
    ... images haven't been removed and as such, short of removing all images, ... if file is not in the database { ... I have the list of files in the directory in an array. ... I know that I need to go through the array and check to see if an entry with the same recordid exists, but I'm not sure how to get the recordid from the filenames. ...
    (comp.lang.php)
  • Re: WORD doc info into FMP?
    ... it appears that each line of the entry follows the format ... number of any given type of field (Location, script, sets etc.) you might ... into a separate record in a database, and a separate related "database 2" ... Ten Nights in a Barroom (New York State Archives) ...
    (comp.databases.filemaker)