Memory management.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fopen()-fgets()

viewtopic.php?t=37400 is one such thread I was referring to.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

EIther I'm missing something here or you are. The problems, since the first post, has been that the file is too big to fit into memory. The offending line in all examples is:

Code: Select all

$fcontents = file ('file.txt');
They way you deal with files that are too big for memory is to read them a line or chunk at a time an process them like that.

To keep it a file, take a look at the PHP manual for the standard file functions -- see fgets() for code examples.

To use a database use can often import the data. MySQL uses the "LOAD DATA INFILE 'file.txt' INTO TABLE file;" syntax. Again check the manual.
(#10850)
Post Reply