I'm new to PHP and trying to make my website as fast as possible. Is there any real difference in speed between including, say, an 8K file rather than a 50k file? I'm precalculating database queries and wondering if I should save the results of each query in a separate file or whether they would be ok all in the same file.
No, the script is not downloading the pages, it is being done on the server and accessing files on the local filesystem is quick enough that the difference in cases like your one will be negligible. As for what you are trying to do, I would suggest separate files to save processing when parsing through the larger file to get the data needed.
Just to add to what krt said there is some overhead when doing includes opposed to having the code already there. Now is the overhead noticable? No not in most people's cases. You'll start to notice it when you're including 50 files on one page.
True but these things matter when you have a lot of visitors. The resources taken by those includes start to actually matter.
I receive 1,000,000 visitors a day I do 50 includes opposed to 1. I will require more server resources if I'm doing the 50 includes. And it will not be a marginal difference it will be several servers more depending on specs. If you scale it enough these things do matter
If you can avoid using include_once / require_once, it will also save a little time. Most of the time all of this is going to be completely negligible. The time that it takes for the information to get from your server to your visitor's browser is where most of the wait comes into play. If you can keep the amount of data you are sending during a request as low as possible it will have a more noticeable effect on speed. Additionally, if you are able to use caching you can save some server resources as well.
it's highly unlikely that he's getting a million visits a day. and if you had read what i wrote, you would notice that it says "in most scenarios".
Ok, thanks for your help guys. I've already got the system in place to use separate files, so i'll stick with that - was just curious as to how much strain it puts on the server. It makes sense that the most important thing is how much data you're sending to the client, not how much you read from the local filesystem. I've only got at most 2 database includes (about 8K each) on any one page, and a couple of tiny includes for templating, so I think I should be fine.
You would be using an advanced caching solution for both the server side scripting and probably for the output too if you had that many visitors so that is out of the question. The point is that if it is more convenient to use more include files, go ahead