![]() |
|
Article Options |
Advanced Plugin Optimization System
Darkwaltz4
Join Date: Oct 2002
Posts: 1,538
Known Technologies: PHP MySQL Javascript XML AJAX SOAP Java C jQuery Drupal Wordpress Chicago
by
![]() New! Attached prototype files to get you started ![]() This is a method you should use to optimize the way your plugins work in your hacks! Background After writing hacks with many many plugins, you run into a couple problems...
Every coder should be familiar with this clever optimization technique, it is even in the vBulletin manual: http://www.vbulletin.org/forum/showt...ghlight=plugin Basically: move plugins to the file system! There is also a "Plugin Accelerator" which does that too. However, now you have a couple dozen FILES to watch after, and it still is too messy for my taste. My next step was to put them all into a single file that gets included in every plugin, but the plugin also has to set some global indicator before including, because the vB system doesn't declare what plugin it is writing to the plugin code itself. It was either many files and 1 code line per plugin, or 1 file and 2 code lines per plugin. I wanted 1 file and 1 line per plugin ![]() Advanced Plugin Optimization System You should know what code is in your plugins, how they work, how to find hooks, etc - I'm not getting into that. I'm also assuming you know how to code PHP in general, and know what functions/OOP I'm talking about, and can look up any you don't. First create the file that will house the plugin code and put it somewhere. I will use the file myhack_plugins.php in the plugins subfolder in the forum root. Create all of your plugins in the ACP plugin manager that you would normally use, and put the exact same single line in each them:
Remember which hooks they use and what code you want to put in them. This optimization is best applied after creating your hack, but not necessarily. Adjust the path to whatever you named it of course. You can also use require to put up errors if the plugins file is missing, but don't use **_once functions if you have more than 1 plugin or it won't work. Create a functions file that has this in it:
This could also be put in the plugins file itself, but then you have to deal with duplicate definition errors, so easier to then refer to the file with
at the top of the plugins file. Remember to change the 'myhack' everywhere to match your hack, preferably to your product identifier. Doing that will also ensure that you don't conflict with other people doing this. Figure out which hook executes very first in your hack. The very first in vBulletin at all is init_startup, and you might want to add a plugin at that hook just to make sure the system works. Remember what your first hook is. Now, in the plugins file, it works like this:
That's it! Keep in mind your names and paths of course. The way it works is that it picks out which hook is executing in a big switch statement, with each entry its own plugin code. However the name of the hook is only reported by extending the vBulletinHook class, so the very first hook executed not only won't have the hookname reported (which is why it is in the default block) but it should also be the place where you extend the vBulletinHook class to begin reporting the hookname for all the rest. Note that at the top the only important lines are the $hookobj line and the require_once line, but the other lines are a good example of what you can do for ALL plugins, such as globalizing $vbulletin and checking for illegal loading of the file by itself with VB_AREA. Use and expand as you see fit (but some sort of acknowledgement would be awesome) ![]() Benefits
You can see this optimization system in use in my vBCredits 1.4rc2 hack here or here. The older version of this (not quite as good, but what I was doing before perfecting this system) is in use in my vBTracker LITE hack here. No members have liked this post.
Last edited by Darkwaltz4; 24 Oct 2008 at 22:37.. Reason: update + prototype files |
||||||||||||||||
Views: 6528
|
Comments |
#2
|
||||
|
||||
Excellent article!
Easy enough to understand (even for me, only starting out!), and a great idea for creators of some of the larger hacks. Just let me get this straight though. You should end up having: 1) ./includes/functions_myhack.php that collates the plugins called by your hack, last one first. 2.) ./plugins/myhack_plugins.php that calls ./includes/functions_myhack.php and switches between the plugin locations for the correct code to insert. 3. All your hooks that you use in myhack_plugins.php switch set in the plugin manager, but with the code to include myhacks_plugin.php And that's it?! Would there be a number of plugins you recommend having in a hack before using this method?
__________________
Awesome. Awesome to the max. No members have liked this post.
|
#3
|
||||
|
||||
![]() You have it down pretty well! Again if you want to see real application of this, look at my demo links of hacks I've used it with. This actually wouldn't be necessary if vBulletin reported the hook that is currently executing, but it doesn't, and the hook class needs to be edited to do so. My other goal I guess, was to provide a solution that end-users wouldnt have to do anything out of the ordinary to install, and certainly not do any file edits. ![]() As for the minimum number of plugins "needed" is kind of blurry. One of the things this allows you to do is work on your plugins all at once in your favorite code editor. You could have one huge plugin in total, but would still be really useful to not copy/paste between the vB Plugin system. Of course, any extras like that would simply compound the problem. Then there is the fact that vB caches ALL active plugins in the datastore which are loaded on every single page as text stored in memory. You help your end-users with database memory, RAM, and speed by using this system, that much more so when they have dozens of hacks installed at once (One site in particular had over 250 hacks installed, and getting anything to load was a ten minute affair - imagine if all of his 1,000 plugins weren't sitting in memory in all their glory?) About the only time you shouldn't bother putting plugin code in this system is if the line of code is one line long anyway and you don't intend to change it very often. About the only thing I can think of like that is the templategroup definition plugin :-p Finally, if at the end of development you see some plugins ended up as one line, then move those ones back into the vb plugin space ![]() Thanks for reading!
__________________
No members have liked this post.
Last edited by Darkwaltz4; 24 Mar 2008 at 01:45. Reason: correction |
#4
|
||||
|
||||
Originally Posted by Darkwaltz4
Some of these articles are so old I've been learning by downloading others' hacks and dissecting them, and using a bit of the old standby of trial and error ![]()
![]()
Originally Posted by Darkwaltz4
Yeah, the file edits (and number of myhack_functions files are another reason this is great.![]()
(But mostly that was gibberish to me! Talk about hooks and I'm pretty vague except for the notion they exist!) Now all that's needed (for me anyway) is to put hooks in the files that have few or none, and use this.
Originally Posted by Darkwaltz4
Hmm, I didn't know it stored the nonactive ones as well. ![]()
I think I'll be using this to convert two of the hacks I have with the most plugins (Andreas' TMS & Interactive Profiles)
Originally Posted by Darkwaltz4
I just use one liners to include function files at the first hook of a file, and for template things - couldn't think of anything else that would go in there and be shortish.![]()
Thanks for writing it! The sharing of knowledge helps everyone. For one thing, we'll not dependent on others to make every little hack we may want or need! I think I'll be using this to convert two of the hacks I have with the most plugins (Andreas' TMS & Interactive Profiles) - should be more educational to try it with someone elses before my own ![]()
__________________
Awesome. Awesome to the max. No members have liked this post.
|
#5
|
||||
|
||||
Aha, you are right: I would like to rescind the statement about inactive plugins being cached. They are not. Doesn't change much of anything else though :-p
Let me know how conversion of those hacks goes ![]() ![]()
__________________
No members have liked this post.
|
#6
|
||||
|
||||
A few weeks ago it was brought to my attention that the system gets messed up if a plugin that executes before your plugins contains other hooks...
So, this new version which I updated the first post with, takes care of that issue. I have also uploaded some prototype files to get you started with, so dont be afraid to use this ![]() As always, if you use this in your hack with success I would love to see it, or if you have questions dont hesitate to ask here or through any method on my profile.
__________________
No members have liked this post.
|
#7
|
|||
|
|||
I highly recommend this system it is a developers dream
![]()
__________________
![]() No members have liked this post.
|
#8
|
|||
|
|||
As a newbie to any type of coding I'm trying to wrap my head around this... I think I know whats going on but am afraid to attempt any of it.
Is this something I should wait to attempt until I have made the transition to the stable release of 3.8? Thanks' Gary
__________________
No members have liked this post.
|
#9
|
||||
|
||||
This will work with vb3.6/7/8. It might also work with vb3.5, but I havent tried it so cant say with certainty.
In a nutshell, what this system does is report to your plugins what hook they belong to. While it seems unneccesary, it allows you to move all of your plugins into a single file with just one repeated include line in your plugins. Doing this has all of the benefits listed in the top post. Note, you may run into problems when trying to use hacks using the two different plugin systems (the one i posted previously, and this current one) if you do, send me a PM and I will explain the solution. I dont want to further confuse people with it unless it applies to them :-/
__________________
No members have liked this post.
|
#10
|
|||
|
|||
Thank you
![]() ![]() No members have liked this post.
|
![]() |
![]() |
||||
Article | Author | Type | Replies | Last Post |
vBSEO Conditional Signatures - Search Engine Optimization Plugin | vBSEO | vBulletin 3.5 Add-ons | 174 | 29 Jul 2011 16:57 |
Administrative and Maintenance Tools Advanced Plugin Manager | akanevsky | vBulletin 3.6 Add-ons | 32 | 03 Jul 2009 02:13 |
Advanced Plugin Manager | akanevsky | vBulletin 3.5 Add-ons | 63 | 12 Aug 2007 21:04 |
«
Previous Article
|
Next Article
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Article Options | |
|
|
New To Site? | Need Help? |
All times are GMT. The time now is 16:59.