0

I am doing some tests (lamp):

Basically I have 2 version of my custom framework.

  • A normal version, that includes ~20 files.
  • A lite version that has everything inside one single big file.

Using my lite version more and more i am seeing a time decrease for the load time. ie, from 0.01 of the normal to 0.005 of the lite version.

Let's consider just the "include" part. I always thought PHP would store the included .php files in memory so the file system doesn't have to retrieve them at every request.

Do you think condensing every classes/functions in one big file it's worth the "chaos" ? Or there is a setting to tell PHP to store in memory the require php files?

Thanks

(php5.3.x, apache2.x, debian 6 on a dedicated server)

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
  • possible duplicate of [Will reducing number of includes/requires increase performance?](http://stackoverflow.com/questions/3423953/will-reducing-number-of-includes-requires-increase-performance) – Pekka Feb 24 '11 at 18:57
  • Related: http://stackoverflow.com/questions/3678177 – Pekka Feb 24 '11 at 18:57
  • Related: http://stackoverflow.com/questions/2059638 – Pekka Feb 24 '11 at 18:58
  • The one big file approach can lead to a speedup for the first run. But with any bytecode cache worth its salt there won't be a significant difference. – mario Feb 24 '11 at 18:58
  • Not answering since it's a massive dup, but the answer you're looking for is *no, it's not worth it*. Install an opcode cache (like APC) and be done... – ircmaxell Feb 24 '11 at 18:59

2 Answers2

2

Don't cripple your development by mushing everything up in one file.

A speed up of 5ms is nothing compared to the pain you will feel maintaining such a beast.

To put it another way, a single incorrect index in your database can give you orders of magnitude more slowdown.

Your page would load faster using the "normal" version and omitting one 2kb image.

Don't do it, really just don't.

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
1

Or you can do this:

  1. Leave the code as it is (located in many different files)
  2. Combine them in one file when you are ready to upload it to the production server

Here's what i use:

cat js/* > all.js
yuicompressor all.js -o all.min.js

First i combine them into a single file and then i minify them with the yui compressor.

Pockata
  • 1,518
  • 3
  • 13
  • 13
  • @yes123, You just need to open the command prompt and cd to your working directory (i presume you know how to do that). Then you run the copy command: `copy *.js all.js` – Pockata Feb 25 '11 at 15:42
  • You can also use a task manager like Grunt to do this, which is helpful in proportion to the complexity of your make script. For instance: you can concat the JS files, run jshint on them, minify them, minify your css, move everything to a staging location, and even run tests. If one step fails, it aborts. Great tool for deploying in one command. – Sean Sep 27 '13 at 08:14