[PHP] Re: read file twice or read into array once?

2001-10-05 Thread John A. Grant

Richard Lynch [EMAIL PROTECTED] wrote in message
046901c14d62$b4c7a0c0$c801a8c0@Lynchux100">news:046901c14d62$b4c7a0c0$c801a8c0@Lynchux100...
 100 lines of 200 chars each is 2 which is 20K which is chump change
for
 RAM...

 Unless you are on a super busy page on a super high-volume server, just
 file() it.

 If you're on a super busy page on a super high-volume server, file() it
 anyway, and then ap benchmark it to see if it's slim enough -- And if
not,
 profile it to be sure it's the file() that's killing you, not something
 else.

I realized it was insignificant amount of memory, but I
wasn't sure about whether this was ok or not in a server
environment.  I will use file() and investigate further if it
seems slow.  Thanks.

--
John A. Grant  * I speak only for myself *  (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: read file twice or read into array once?

2001-10-04 Thread Richard Lynch

100 lines of 200 chars each is 2 which is 20K which is chump change for
RAM...

Unless you are on a super busy page on a super high-volume server, just
file() it.

If you're on a super busy page on a super high-volume server, file() it
anyway, and then ap benchmark it to see if it's slim enough -- And if not,
profile it to be sure it's the file() that's killing you, not something
else.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
- Original Message -
From: John A. Grant [EMAIL PROTECTED]
Newsgroups: php.general
To: [EMAIL PROTECTED]
Sent: Thursday, October 04, 2001 5:29 PM
Subject: read file twice or read into array once?


 I have a file containing ~100 lines of text, each perhaps 100-200
 characters in length.  I need to retrieve line $n from the file, where:
 $n = $julianday % $nlines;

 $julianday = today's date (from localtime[7])
 $nlines = no. of lines in the file

 Method A
 0. fopen() the file
 1. read the file line by line with fgets() and count the lines ($nlines)
 2. compute the required entry: $n=$julianday % $nline
 3. rewind() the file and read it again until entry $n is found
 4. fclose() the file

 Method B
 1. read the entire file into memory: $lines=file(myfile)
 2. compute the required entry: $n=$julianday % count($lines)

 I appreciate that this depends on the no. of lines in the file and
 the size of the file. What I'm looking for is opinions on whether
 the use of file() is more efficient than fgets(). It needs more memory,
 but it eliminates reading the file twice.

 Thanks.

 --
 John A. Grant  * I speak only for myself *  (remove 'z' to reply)
 Radiation Geophysics, Geological Survey of Canada, Ottawa
 If you followup, please do NOT e-mail me a copy: I will read it here





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]