require versus db select: speed difference

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
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

require versus db select: speed difference

Post by koen.h »

A database request is essentially reading from disk. So is including a file. Anyone knows which is faster? I assume require but require_once is very slow too.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: require versus db select: speed difference

Post by Eran »

It depends. Databases use all sorts of query optimizations and keep a cache in memory. If there is a cache hit, loading from database is probably faster (no need to load from disk) - so if you request the same resource a lot, you might get better performance that way.
You should probably profile both cases if performance is important.
Post Reply