In-Portal Developers Guide

This is a wiki-based Developers Guide for In-Portal Open Source CMS. The purpose of this guide is to provide advanced users, web developers and programmers with documentation on how to expand, customize and improve the functionality and the code the In-Portal software. Please consider contributing to our documentation writing effort.

K4:Regular Events

From In-Portal Developers Guide

Revision as of 06:09, 28 November 2010 by Dmitry (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
Unit Configs Unit Configs
Статьи в этой категории

In-Portal has functionality that allows running Events on a regular basis. These are called Regular Events and can be triggered with specific repetition (specified in seconds). There are 2 ways of triggering these events by the system:

  • from "tools/cron.php" script;
  • before or after showing the page content to the user.

Each of the ways has it's own pros and cons which important to know to select the best way of reaching designed goals. There is a way to control which way is default via UseCronForRegularEvent option in In-Portal configuration.

Using Cron

The main advantage of using Cron to trigger and process regular events is that website users won't be waiting until these events are finished executing. This approach is good for cases when the results of event execution can't be or shouldn't immediately noticed after long processing. Good example would be a user rating or other calculated numbers that are gather and processed using lots of data. Even if there is a delay with thee kind of data update it will be critical to the Front-End users and will save processing time requires for each page.

To setup cron, you would need to add the following command to the crontab file (using "crontab -e" command) of the current server user:

wget http://server_address/tools/cron.php -O /dev/null > /dev/null 2>&1
  • server_address - complete URL your In-Portal website (ex. "www.intechnic.com/test_project").

In this case regular events won't be triggered when users are visiting the website, instead they will be triggered by calls from "tools/cron.php" file (use file supplied with In-Portal).

Not Using Cron

In case if you decided not to use cron or it simply can't be enabled due to server restrictions then you can still trigger Regular Events by default when your website is visited by user. This approach is less effective then cron, but requires no additional changes to the website or access to the web-server.

Additionally, you can setup an After Hook on the following Events:

  • adm:OnStartup - for execution before webpage displayed to the user;
  • adm:OnBeforeShutdown - for execution after webpage displayed to the user;

It's recommended to use shown above approach when Event needs to be always executed not depending on the time interval.

Example

First the actual Event needs to be programmed (in corresponding Unit) and then it can be registered in RegularEvents section of Unit Configuration file:

'RegularEvents' => Array (
	'membership_expiration' => Array ('EventName' => 'OnCheckExpiredMembership', 'RunInterval' => 1800, 'Type' => reAFTER),
),

Name of the key should unique among all other Regular Events through the system.

Option name Description
EventName (string) Event name in current Unit Configuration file.
RunInterval (int) Interval for triggering regular event (in seconds).
Type (int, const) Defines when regular event should be triggered in relation to the page output:
  • reBEFORE - before page output;
  • reAFTER - after page output;

Translated from: revision 1074