En:What is the difference between scrips, plugins and PAX?

From phpCMS

Jump to: navigation, search

Question: What is the difference between scrips, plugins and PAX?

Answer:

Contents

[edit] Plugins

Plugins are executed at a stage, where phpCMS assembles the page completely new. This means that from within a plugin you have access to all "phpCMS internals" like the menu array etc. So whenever you want to manipulate the way phpCMS creates a page, you have to do it within a plugin.

Examples: Inside a plugin you can modify the menu structure or load additional subtemplates or define additional content fields etc.

While plugins can run only whenever a page is created newly, there are two ways to include a plugin:

  1. As a "dynamic" plugin. This means, that the final page will not be cached by the phpCMS internal caching system and therefore everytime the page is called, phpCMS generates it anew from scratch and the plugin gets executed.
    Example: If you would like to modify the menu structure dynamically in dependence of the current user, you would have to do this via a dynamic plugin, so the output does not get cached. Everytimes the page is created, the plugin would have to check some conditions (e.g. the username) and then modify the menu-structure before phpCMS creates the menu-output.
  2. as a "static" plugin: This means, that phpCMS executes the plugin only once and then the final page including the output of the plugin is cached as static HTML code. The next time the same page is called, phpCMS reads the cached output and delivers it to the user without executing the plugin again.
    This is useful for plugins, which modify the page and whose output is not dependent of any "dynamic" factors.
    Example: A plugin that creates a breadcrumb navigation line on every page. Such a plugin needs to have access to the menu structure in order to calculate the correct breadcrumb line. Therefore it has to be a plugin and not a script. And the output is static and doesn't change everytime the page is called, so it can be included as a static plugin.

[edit] Scripts

Another method to include the output of PHP code into phpCMS generated pages are scripts, which are included via the {SCRIPT} command into content files. Scrips are executed by phpCMS at the end of the page creation, when all other tasks like menu creation, tag replacement etc. are done. phpCMS creates the complete output page with placeholders at the the places where the content of the included scripts should be fitted in. Then in a very last step phpCMS runs all included scripts and replaces the placeholders with their output. Thus phpCMS can cache at least the static part of the page, with other words the version where everything is assembled except for the script outputs. This kind of caching is called "dynamic caching". Whenever a page is called, which contains scripts (but no dynamic plugins) phpCMS can fetch this almost-complete version of the page from the cache, run only the included scripts and paste their output on the designated place and deliver the final page to the user.

This makes the page creation much faster than creating the entire page from the scratch, but on the other hand as the page is already almost complete a script can't manipulate the page creation process anymore.

When including a script via the {SCRIPT} command phpCMS take care that the included script runs under the same environmental conditions as if it would run "stand alone". The script-command is the right choice when you want to include dynamic content which does not need to manipulate the page creation process of phpCMS. Examples are forums, guestbook and most other public available php scripts

Another example: If you want to display the current date & time on a page, it could be done either with a dynamic plugin or with a script. The result would be the same, but when implementing it as a dynamic plugin, phpCMS won't be able to cache the pages while the implementation as a script would enable phpCMS to cache the page dynamicaly.

[edit] PAX

PAX comes in two variants: PAXPHP and PAXTAGS

PAXTAGS are like standard tags that get replaced by phpCMS, yet with a little twist: They can take additional arguments and will have dynamic results. The best example for this would be the tag 'PAXLASTMOD', which will be replaced by the modification date of the content file it's called in, formatted the way the user specifies. Caching is not influenced by using PAXTAGS - a page containing such a tag will still be able to be cached statically. More details about the available PAXTAGS can be found on the PAX documentation page. Note that in order to use PAXTAGS, you have to allow them in the configuration.

PAXPHP on the other hand is a little bit different. It's not - as the name might suggest - an own language, but the ability to include (short) PHP code pieces into your pages. Much like with scripts, the usage of PAXPHP will make a page cacheable dynamically only - in fact, including PAXPHP blocks is like a mixture between using scripts (dynamically cacheable) and plugins (read-access to phpCMS-internal variables. Again, the PAX documentation page holds further information.

[edit] Quick overview

[edit] static plugins

advantages:

  • fasted way, as the output gets cached statical (the filenames in the cache directory get the extension '.htm'). A page containing only static plugins (and no dynamic plugins, scripts or PAX) will be cached as a static HTML page and whenever it's called and available in the cache, all phpCMS has to do is:
  1. check if the page in the cache is still valid (it newer then the contentpage)
  2. read the cached page from disc and deliver it directly without any further modification to the user
  3. terminate phpCMS
  • from within the plugin you have full access on the page creation of phpCMS - so you can read & create content fields, read & modify the menu structure, templates, manipulate or create tags etc.

disadvantages:

  • As the output gets cached statically it can't be used for dynamic output which should change everytime the page gets called.

[edit] scripts

advantages:

  • second fastest way - and the fastest way to generate dynamic output.
    Pages with included scripts (but without dynamic plugins) will be cached dynamically in the phpCMS internal cache (file extension '.dyn' in the cache-directory). The cached version of the page is completely prebuilt and the only thing that is missing is the output of the included script(s).

Whenever such a page is called and available in the cache this is what phpCMS does:

  1. check if the page in the cache is still valid (it newer then the contentpage)
  2. read the cached page from disc
  3. execute all included scripts and replace the placeholders in the cached version with the script-outputs
  4. deliver the output without any further modification to the user
  5. terminate phpCMS

disadvantages:

  • As the page is already almost completely assembled, when reading it from the cache, you can't manipulate the way phpCMS assembles the page from within an included script.

[edit] dynamic plugins

advantages:

  • they are the only way to manipulate the page creation of phpCMS every time a page gets called.

disadvantages:

  • as pages with included dynamic plugins don't get cached at all, it's the slowest method. Before using a dynamic plugin, think twice if the problem can't be solved by an included script or even a static plugin.
    Evertime a page with a dynamic plugin is called, phpCMS has to create the entire page from scratch, meaning that it has to read the content file, all templates, tagfile, menu-file, menu-template etc. pp. and put everything together.

[edit] PAXTAGS

advantages:

  • Very short, no programming-knowledge needed
  • 'static' cacheable

disadvantages:

  • Only limited number of tags available

[edit] PAXPHP

advantages:

  • No additional files needed
  • (Read-)Access to phpCMS internal data structures

disadvantages:

  • You can't actively change (most) phpCMS-internal data structures and have the change influence the resulting page
  • 'dynamic' caching is needed, because phpCMS will execute the PAXPHP block on each request

Diese Seite in anderen Sprachen: Deutsch

Main Page: FAQ MainPage | Top Page: English FAQ MainPage

Personal tools