user481913
user481913

Reputation: 1018

Is this php script a potential memory hog?

Is it normal for a php script to include/load some 100 files at the start ? These files are related to database, helpers, utilities and functions for common tasks. This is done through the use of require_once .

I'm just asking this in the context whether this is a normal practice in other php scripts(open source or commercial) as well . Haven't use any php frameworks as yet so i'm not sure how many files they load.

i'm going to use this script on a vps that has a shared cpu core , 1 Gb Ram, 40 Gb hard disk space.

Now i know this question might have many other variables such as how cpu intensive each file is, however, my basic question here is is it normal for any script to load or initialize about 100 files into memory at the start?

Please let me know if you need any further information.

Upvotes: 0

Views: 104

Answers (2)

Frank Farmer
Frank Farmer

Reputation: 39386

Is it normal for a php script to include/load some 100 files at the start ?

That's not totally abnormal. The HTMLPurifier library alone is dozens of files, most of which are probably loaded during normal use.

Having 100 separate require_once lines including each file one by one, however, is bad code smell. As David says, use an autoloader.

Also, don't include code that isn't going to be used. I once worked on a project that naiively included the source of every page at startup time -- including view/controller code for pages that weren't being displayed. Undoing this (and instead loading only the view/controller being used) lead to measurable performance increase.

Also, an opcode cache like APC will reduce include overhead. Consider using one if possible.

Is this php script a potential memory hog?

You tell me. Measure. Profile. Experiment. Any armchair guesses that we can provide about the performance of your particular application are worthless. Measuring is easy. Use XHProf, or simply call memory_get_peak_usage(true)

Upvotes: 3

Lusitanian
Lusitanian

Reputation: 11132

No, that's not normal practice. Use an autoloader.

Upvotes: 1

Related Questions