tags:

views:

49

answers:

4

You can reduce the number of HTTP requests to speed up your site, such as css sprite images. I'm wondering does reducing the number of php includes/requires also speed up your site or reduce server load? For example, I have a index.php with <?php include './file.php'; ?> If instead I copy and paste the code from file.php and just put it into index.php, thus removing the include code, would it reduce the server load? This might make things less organized, but if it does reduce server load I might need to do that. For a small to medium sized site, I assume there might not be a difference, but how about for high traffic sites?

EDIT: Due to some circumstances, it's usually not cached, so would I see a benefit assuming pages aren't cached. I would say the page receives 10+ pageviews per second on average.

Thanks in advance.

+1  A: 

All includes are done on the server—essentially, PHP is copying and pasting the file for you. It really doesn't require much processing power. If you want to reduce load, look into minifying and merging your JavaScript and CSS files.

Samir Talwar
minifying javascript and CSS files may increase page speed for visitors, but it doesn't reduce server load
Andriy Bohdan
All JS and CSS are already minified.
rein
@Andriy: Pretty sure it should. Less requests = less load. My server went down a few days ago because I didn't take exactly that into account. Glad to hear it, @rein.
Samir Talwar
minifying javascript and CSS doesn't reduce the number of requests. It reduced only size of files.
Andriy Bohdan
@Andriy: You should be merging them too—multiple JS and CSS files should be combined into one, jQuery should be offloaded onto Google if possible and cache expiry time should be set to approximately infinity years in the future.
Samir Talwar
+1  A: 

Theoretically yes, it will speed things up, but in practice the difference will be immeasurable.

Combining the files will reduce the amount of disk activity on the server: for each request, it only has to examine one file rather than two.

That will decrease server load, and hence speed up the response, but on a non-trivial site - especially one that's talking to a database - the effect will probably be negligible.

On a busy site the files will be cached in memory, making the value of combining them even smaller.

RichieHindle
Due to some circumstances, it's usually not cached, so would I see a benefit assuming pages aren't cached. I would say the page receives 10+ pageviews per second on average.
rein
I'm talking about the operating system's disk cache on the server machine. I'm not talking about browser caching.
RichieHindle
A: 

The reduce will be too small to be noticed.

It would make more sense to use opcode cache instead.

http://php.net/manual/en/book.apc.php

Andriy Bohdan
Due to some circumstances, it's usually not cached, so would I see a benefit assuming pages aren't cached. I would say the page receives 10+ pageviews per second on average.
rein
Opcode cache works on lower level than page cache or object cache.Php files are transformed into binary code which is cached once and the server doesn't need to reread php source files each time when page is opened
Andriy Bohdan
A: 

The reason that there's a general recommendation to reduce the number of HTTP requests is because of the typical latency involved with each one. A remote call is generally much slower than a local one. Unless you're storing your included PHP file on a remote server (which you probably aren't) you will see virtually no benefit to inlining the code. In fact, you will probably suffer with a much more difficult development task of maintaining multiple copies of the contents of file.php.

Jono