Many CMS systems which rely on third parties for much of their code often build "plugin" or "hooks" systems to make it easy for developers to modify the codebase's actions without editing the core files.

This usually means an Observer or Event design pattern.

However, when you look at systems like wordpress you see that on every page they load some kind of bootstrap file from each of the plugin's folders to see if that plugin will need to run that request. Its this poor design that causes systems like wordpress to spend many extra MB's of memory loading and parsing unneeded items each page.

Are there alternative ways to do this? I'm looking for ideas in building my own.

For example, Is there a way to load all this once and then cache the results so that your system knows how to lazy-load plugins? In other words, the system loads a configuration file that specifies all the events that plugin wishes to tie into and then saves it for future requests?

If that also performs poorly, then perhaps there is a special file-structure that could be used to make educated guesses about when certain plugins are unneeded to fullfil the request.

Any ideas?

If anyone wants an example of the "plugin" concept you can find one here.

  • HMVC - not an answer, but related.
    – yannis
    Commented Jan 20, 2012 at 18:29
  • +1 Good question! I would perhaps focus the scope a bit just so it seems less open-ended - anyway just a thought. Commented Jan 20, 2012 at 18:31
  • PHP's architecture makes any real caching difficult -- every request is a new program essentially, at best you'd have to read a plugin graph off of disk. Which is kind of what you are doing already anyhow . . . Commented Jan 25, 2012 at 16:41

2 Answers 2



I really like this question so I will take some time to answer it. The first thing to know about wordpress and CMS systems like it is that they are not built for speed. They are built to be easy to use easy to configure. People that normally use a wordpress site want to be able to easily edit there site and throw new things into it togeather or dont even know how to program. So things like scanning all the plugins asking them if they need to do something with this page or not is a resource risk can be taken to give very easy to use functions to the CMS

If you are trying to build a CMS and find an easy way to get both of best worlds I have not found a way around the issue with out a little bit more work Here is an idea I have had That maybe able to help you a little bit. For each of the new plugins that are added to the site when they are installed or activated in the admin panel they should write to a file stating when they need to do something and what they need to do. When they are deleted they scan for there entries and delete them. The admin system should also have a method of checking to see if a plugin is missing and delete lines no longer associated with the system. THis way you will be able to get ease of use for simple click installs but will give you more speed because insteed of scanning and asking each plugin if they need to do something at this point in time they would have built a list that you can search for and use as your guide.


A really good question!

Especially when it comes to PHP since we dont really have a shared memory and we are bound to the HTTP REQ<=>RESP "flow".

... if I am not wrong, please don't hesitate to correct me if ...

With PHP 5.3+, you can take advantage of namespaces to optimze the performance "load"/"overhead" of plugin-classes(files).

During each PHP request, the "use" keyword in combination with correct "namespace" declarations will make sure that only those classes are "read/loaded/parsed" which are required for the current request.

This is sadly not done (to my knowledge) with any kind of PHP-internal-optimization. (correct me if I am wrong)

Therefore it depends on your OODesign skill not to produce monolithic classes, cause that would defy any class-loading-optimization using namespaces.

Additionally you can take advantage of .phar packages, which fit very well into the namespaces/use-keyword concept.

Ref's: PHP Namespaces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.