Forum Moderators: coopster

Message Too Old, No Replies

SQL query vs. PHP file include

Speed comparison?

         

sami

10:42 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



In efforts of trying to figure ways to optimize one php script I was just wondering - is anyone able to tell in a general level, which is faster (in relation to pure exceution speed and server load): making one or two SQL queries (nothing very complicated, like "Select A,B,C from table where ID=ZZ And valueY=XX") OR loading a file with either fopen or include command and passing it's contents into variable? If this process is done let's say, 50 000 times a day, which would be the way to go. (and just to elaborate a bit - if using the file method, the contents of the file would be changed only by admin = very rarely, so it would only require loading the info in the file, not parsing it in any way)

At least in case of high server loads I've noticed that SQL related connections usually become slower at first, while the other parts of the site with plain html pages work properly/rather fast. (this might also indicate that sql server settings could be improved, but is another story)

jollymcfats

10:59 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



A lot of effort goes into into a SQL query- opening files, setting up network sockets, interprocess communication, packing data into strings, unpacking, parsing, the actual data querying... By comparison, reading in the contents of a file is almost no effort whatsoever.

But, for a site that makes general use of a database, usually the SQL query approach is much more straightforward to maintain and understand than including a static file. With the static file, you need to remember to update it, maybe maintain web-writable permissions, where it is, etc. Lots more to go wrong.

With 50,000 hits (= 1 every 2 seconds) its not really anything to worry about. I'd say go with the SQL approach, and if and when you experience performance problems, then consider optimizations like including static files.