is it a safe assumption?

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

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

is it a safe assumption?

Post by newmember »

i'm doing simple file-based guestbook.

$numOfRecs=filesize($path_of_guestbook) / SIZE_OF_RECORD;
this is how i determine total number of records in guestbook
(each record has fixed size)

is it possible that the above line will fail for other OS or other filesystems?
i was thinking of compressed file systems...

what do you think about this?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if your talking about xp's compressed files, i 'think' it would fail.

i say this because i think the stat type of file info is stored in the MFT, so i think checking for filesize
wouldnt actually uncompress the file just to check, it would just use the info in the MFT.... it wouldnt be hard to check.

but, why limit yourself to having to make entries a specific size?
you could just use a delimiter and use explode() to seperate the data, unless your just trying to find an efficient way of checking how many entries w/out openeing the file and processing it. but you could always keep a seperate log file that just has a single number representing the number of entries, which would be a resource friendly way to check.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

ok i see
it is better to be on the safe side then

(with my first try i kept a counter in separate file but then i wanted to make things simplier.)
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

well, do you need to display the number of entires on pages where you dont need to display the actual entires? often?

if you only need to display the number of entries on pages that actually show or in some way use them, just count them.
its uses very little additional resources if your already opening and reading the entire file.

Code: Select all

$data = file_get_contents('entries.db');

$entries = explode('|', $data);

$num_entries = count($entries);
unless you expect the database file to get very large, those 3 lines of code execute pretty darn fast....
Post Reply