Including Function Script File - Memory Issue ?

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
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Including Function Script File - Memory Issue ?

Post by anjanesh »

I have some 1000 functions that are required in many scripts. Many functions are required by all scripts but not all functions are required in a script.
So I put these functions in a functions.php script and this file is included in the scripts.
If a script requires just one function from the functions.php will the other 999 load as well ? Will this be a memory issue ? If so then how do I avoid this ?
Thanks
Anjanesh
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

if im not mistaken they all will be loaded at ruintime, but its not outputted to the user so i dont think it will cause any issuses, but thats just my opinion

another soultion would be to break up your functions into individual files(functionName.txt) then just include the required ones, or build classes that contain clusters, like 50 functions but how you have it now i dont think will cause a problem.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

1000 functions!

How do you remember what they all do?
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

anjanesh,

I found it easier to create multiple files for example:

fncStrings.php
fncEmail.php
fncDb.php
etc..

This breaks my library into about 15 or 20 files and I only include what I need at that point, seems to me including a file with 1000 functions, which I am guessing is about 5k-15k lines of code would slow your applications to a crawl. Now I could be wrong on this, but it is just my opinion to only include what you need. Waste not want not ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Agreed Saethyr, most of my functions are broken into seperate groups. Easy to swallow chunks, so to speak. Then I have a few include files that pool several commonly used ones together, so all I have to do is load the pool, instead of loading 10 different includes..
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thats true indeed. I just wanted to know about the memory issue when it comes to running it on the server. If all the 1000 functions are included with the calling script or only the ones that are called.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from what I've seen, the function will exist, but not parsed until it is referenced/called within the run code.
Post Reply