[Pmwiki-users] PHP Question: Storing Function Address in $SquareBrackets[]
Tue Apr 6 04:55:34 CDT 2004
Some add-on's are fairly lengthy, take up processing power, memory, and time to execute. I wonder if there might be a way to have an add-on execute ONLY if called to do so. Currently, I believe most of the include_once("script.php") scripts get executed regardless of whether they are used on the page or not. If you have a lot of add-on's running, this can slow down the system quite a bit.
One possible solution is creating a PageName.php script in your local/ directory, and putting the include_once("script.php") line only in the Groups/Pages you need it.
However, you may want some scripts to be available across the site, on any page / group. So how can you make it so they won't execute (waste cpu and memory) even though they may not actually be required on the page?
I'm not picking on the calendar script, but lets just use this as an example. Currently, if you have calendar enabled, and you view source on any WikiPage, you'll see a huge list of in-line css stuff. This just serves as a reminder that every time you view a wikiPage, the calendar script is running through it's paces, and inserting the necessary header code on your page "just in case" there's a calendar component on the page.
This applies to any script .. not just the calendar script.
It would be nice if all the calculations, variable declarations, and particularily the in-line styles would only execute IF the [[calendar:]] component is actually found in the wikiText.
I found a partial solution in reviewing the code for the random quotes script. It stores the address of the function in the SquareBrackets array instead of the function's output, this way it takes no space, and the function isn't actually executed unless an instance of the [[randquote:]] directive is found within the WikiText.
Unfortunately, this doesn't work in more complex scripts.
$SquareBrackets = [[calendar:]] = &my_function();
This works great for that example because there are no parameters being passed in the double-brackets. But suppose you had something like [[calendar: month=3 wrap=1]] .. now you need to rewrite the square bracket syntax something like this:
$SquareBrackets = [[calendar: *some regex stuff here*]] = my_function($1);
Where $1 represents the stuff after [[calendar: . Now the &my_function idea doesn't work because you are passing the function a variable.
I'm very new to php programming. I'm just trying to figure out how I can optimize my code and functions so they don't waste resources. If I include 10 add-ons, and only use one per page, then every page is executing 9 bits of code unecessarily. Seems like an awful waste to me
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pmwiki-users