Separation of included functions will improve PHP performance?

I have a main php file with a main class. Also in this class I do require_once ("func.php"); which has many useful features for my site.

The size of func.php is very large because there are many functions for different actions on different pages . But I include it on every page, because including one called by the main class. What do I need to do to optimize it?

Rewrite func.php in OOP and use something like "$ funcs-> my_func ()" in the main class? Will I win some work? Functions that were not called would not take up memory and processor time?

Or do I need to rewrite func.php for many files and call them on the specified page? For example: for "about.php" I will include "about_func.php" with the necessary functions. But this is not convenient, I think ...

Please help me :) And sorry for my eng :)

+4
source share
3 answers
  • How big is func.php? Are you sure the size of the problem.
  • This is similar to the question of performance / optimization at heart. Are you sure optimization is justified? Did you evaluate the effectiveness of your page and prove that the inclusion of this large function file is to blame for its slowness?

I suggest you answer 1 and 2 to yourself before continuing. If the motivation for your question is a cleaner design and modulation, then yes, I would agree that splitting the "utils" file in error into smaller files that share responsibility or a common area of ​​relevance is a good idea. If, on the other hand, this is a case of premature optimization, then you better leave unsatisfactory "func.php" (hey, sometimes it's nice to have a large shared utils file if it doesn't harm you).

+4
source

Divide it into oop classes and use the __autoload function for PHP5: http://www.php.net/manual/en/language.oop5.autoload.php

This wil loads classes only when necessary, and you don't need to worry about including all the necessary files. This will not give you any performance benefits, but it’s easier to manage smaller files for one purpose than a large one with several functions that are independent of each other.

+4
source

Do you have PHP accelerator enabled?

Because they store the “compiled” version of func.php in memory, which should speed things up without any code changes.

Although I recommend OOP, this is not for performance reasons.

+3
source

All Articles