Computer Science Canada

PHP 'include' speed differences

Author:  DanShadow [ Wed Nov 17, 2010 3:01 pm ]
Post subject:  PHP 'include' speed differences

Hey all,

Up until now i've been doing (most of) my PHP programming in 1 file, but i've been thinking it would be easier to 'include' a series of PHP files for additions I make to the code (easier both for me later on in development, and easier if I choose to work with somebody else on a project).

So.. my question is (to anybody who knows about speed differences when it comes to PHP 'include' statements), what kind of page-loading speed differences can I expect from:
- a multitude (dozens) of individual 'include' statements
- several batched 'include' statements
- a couple include statements, with all fore-mentioned 'include'd PHP files in the main PHP file

I've heard that with a multitude of individual include statements it may take 10x longer to load a page.

If anyone can give me any info on page load speeds, I'd appreciate it! Very Happy

Author:  DanShadow [ Thu Nov 18, 2010 10:08 am ]
Post subject:  RE:PHP \'include\' speed differences

B_u-m_P

Author:  [Gandalf] [ Sat Nov 20, 2010 11:00 pm ]
Post subject:  RE:PHP \'include\' speed differences

I wouldn't worry about it. include() just evaluates and copies the specified file, so as long as you don't have some crazy circular dependencies the speed should be comparable. That doesn't mean you should put every function in a seperate file. Just split things up logically.

What I would worry about with includes, however, is making sure that someone can't arbitrarily load files on your server by changing the parameter. Razz

Author:  yoursecretninja [ Sun Nov 21, 2010 12:33 pm ]
Post subject:  RE:PHP \'include\' speed differences

As someone who does PHP programming for a living in a team environment, I can tell you that not only do includes not have any noticeable impact on real world performance, they are an absolute must if you don't want your code to become unwieldy and repetitive. Using includes prevents you from constantly rewriting the same code all over the place, which makes programs difficult to follow and a nightmare to modify, which is completely unacceptable in a team environment.

Presumably, you're doing web programming. You should be much more concerned with inefficient programs, having too many db queries (specifically write queries), unoptimized assets, and too many http requests.

Author:  DanShadow [ Sat Dec 11, 2010 4:45 am ]
Post subject:  RE:PHP \'include\' speed differences

Thanks yoursecretninja, that is a perfect answer.
Thanks for that perspective as well, im sure it will come of use.


: