3

I have about a 2000 line functions file, and I have realized I can split it up into a bout 4 files, and only include the one's required. At the moment it is very neat, and ideally I would like to leave it that way, however if speed increases can be gained I would like to only include the different sections on particular conditions.

My question is basically, would it be quicker to have an if statement and only load the php functions needed. Speed is a factor, as this library is called in an ajax polling situation.

genesis
  • 50,477
  • 20
  • 96
  • 125
Josh Mc
  • 9,911
  • 8
  • 53
  • 66
  • 1
    http://stackoverflow.com/questions/2298196/php-include-file-size-performance Does not answer all the question, but still gives an idea. –  Jul 29 '11 at 00:38

1 Answers1

6

best approach would be to divide all your code into meaningful folders/files/classes/functions. This serves the purpose of maintainable and readable code.
And then use some kind of cache like APC whih removes the problem of many includes/IOs almost completely.

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
  • 5
    Split not for performance but to increase the quality of the code. +1 – hakre Jul 29 '11 at 01:27
  • For the most part my includes, invoke function definitions more then variable definitions. My understanding was APC cached variables, not so much functions, is this correct? – Josh Mc Jul 30 '11 at 00:27
  • 1
    @jezternz he actually does both, and it is a separate thing. caching variables you have to invoke by calling a function from within PHP, while caching your code happens automatically once you activate APC. You can regard this as two separate systems (which happens to share some code). – Itay Moav -Malimovka Jul 30 '11 at 00:29
  • cheers Itay!, I may have to look into a custom server, as I don't know how much control my current web server gives me and I am not sure if I will be able to install APC, but while my project is in development I probably don't need to worry about it. – Josh Mc Jul 30 '11 at 00:32
  • 1
    @jezternz how big is your project going to be (code base, number of users) you might be worried about what we call "premature optimization" (which is eval's brother). – Itay Moav -Malimovka Jul 30 '11 at 00:35
  • APC is great advice. There is a HUGE difference when requiring code with and without an op-code cache system. Parsing and compiling on every request is really slow, at least when comparing to not doing it thanks to APC. (100 to 1 in my tests) – Sebastián Grignoli Jul 30 '11 at 01:22
  • As this is an experiment as much as anything. It could potentially stay that way, only having a few users when testing. Or if it took off (i wish!) potentially hundreds of users polling in ajax simultaneously. – Josh Mc Jul 30 '11 at 09:46