PDA

View Full Version : Php Processing/Parsing Question



greenie
08-30-2008, 05:46 PM
Okay, just realized that this probably doesn't belong in an "Advanced Scripting" forum, but I'm already here, so what the heck.

I've been programming sites with php for a few years now, and never really thought about this question before, so I feel a bit ignorant. Maybe it is because I have done more programming on already developed php applications, and am only recently begun to develop my own from scratch.

Okay, onto the big question. Say you've got this big old php script that has all of your application functions defined on it. Many of the functions contain multiple database queries. This big old php script is being included on every page of the site. Now, does that mean that all of those db queries are being executed for every time any of the site pages load, or does it mean the db queries are only executed for pages which actually call on, process, any of the applicable functions that contain the queries?

I'm guessing the db queries are only executed when the functions are actually called up, but maybe I have been totally wrong on that one. I'm thinking that I'm right because that would explain why almost all php applications contain misc. functions to one script. But if I'm wrong, then I think I'm going to start making a functions directory, and putting each function in a file, or something. Kind of makes OOP look all dreamy : )

Eriksrocks
08-31-2008, 05:59 PM
Okay, just realized that this probably doesn't belong in an "Advanced Scripting" forum, but I'm already here, so what the heck.

I've been programming sites with php for a few years now, and never really thought about this question before, so I feel a bit ignorant. Maybe it is because I have done more programming on already developed php applications, and am only recently begun to develop my own from scratch.

Okay, onto the big question. Say you've got this big old php script that has all of your application functions defined on it. Many of the functions contain multiple database queries. This big old php script is being included on every page of the site. Now, does that mean that all of those db queries are being executed for every time any of the site pages load, or does it mean the db queries are only executed for pages which actually call on, process, any of the applicable functions that contain the queries?

I'm guessing the db queries are only executed when the functions are actually called up, but maybe I have been totally wrong on that one. I'm thinking that I'm right because that would explain why almost all php applications contain misc. functions to one script. But if I'm wrong, then I think I'm going to start making a functions directory, and putting each function in a file, or something. Kind of makes OOP look all dreamy : )

Functions only execute if they get called. So if the page you're browsing doesn't call any certain function, whatever is in that function will not execute. :)