include/require vs. readfile

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
ruthsimon
Forum Newbie
Posts: 19
Joined: Mon Aug 19, 2002 5:44 pm

include/require vs. readfile

Post by ruthsimon »

Most reference books/posts/documentation/etc. recommend using include() or require() to add, say, a common header to multiple php pages.

What's wrong with using readfile()?

Thanks, Ruth
User avatar
Xelmepa
Forum Commoner
Posts: 41
Joined: Sat Aug 24, 2002 3:02 pm
Location: Athens, Greece
Contact:

Post by Xelmepa »

I guess the authors know more than us, but taking a quick glance at readfile's documentation:

Description
int readfile ( string filename [, int use_include_path])


Reads a file and writes it to the output buffer.

Returns the number of bytes read from the file.

We see that readfile also returns filesize, which we usually don't need, therefore becoming slower than include. But I bet there's more to it.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

well readfile is a viable solution, if the file your are reading from is strictly html with no php scripting in it. if you want to include a file with php script then you must use include and/or require
Post Reply