Php – Designing web-based plugin systems correctly so they don’t waste as many resources

design-patternsobserver-patternPHPpluginsweb-applications

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.

Best Answer

Xeoncross,

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.

Related Topic