PDA

View Full Version : Benefits from placing hook code in external files?


JamesAB
06-12-2015, 12:56 PM
Is there any benefit from putting hook code in an external file?

I see some developers just put something like this in the Plugin Manager hook location:
require(DIR . '/includes/some_hack/hooks/forumdisplay_complete.php');

And then put their code in that external file.

I use xCache for caching PHP files, so I can see the benefit of those files being cached, however I see the overhead of adding another file to the page.

I was wondering if there are any performance (or other) benefits to using this method as opposed to just putting the full code into the Plugin Manager. Or are there any performance drawbacks to this method?

Thanks,
James

kh99
06-12-2015, 01:36 PM
I'm curious about that too. I don't have that level of knowledge about php, but my guess would be that if you have a cache that can cache the parsed php then it could improve the performance over having to parse the code from the database every time.

cellarius
06-16-2015, 09:10 AM
The overhead of including a php file depends on the size and number of files, but for your average addon I'd say it's rather negligible.

Why do it? It is simply way more comfortable to develop addons using your favourite editor and just hit the save button over having to copy the code to the AdminCP input box every time.

The main benefit regarding performance is that you have to keep less code in the datastore cache (only the include vs. all of the actual code). Overall, I'd say the tradeoff is well worth it.