K4:Regular Events
From In-Portal Developers Guide
m (категория) |
Current revision (06:09, 28 November 2010) (view source) (Translating) |
||
(One intermediate revision not shown.) | |||
Line 1: | Line 1: | ||
{{toc | category = Unit Configs | sortkey = 005.001}} | {{toc | category = Unit Configs | sortkey = 005.001}} | ||
- | + | In-Portal has functionality that allows running [[K4:Events|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 "'''<code>tools/cron.php</code>'''" 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 [[K4:Configuration#UseCronForRegularEvent|UseCronForRegularEvent]] option in In-Portal configuration. | |
- | + | ||
- | + | == Using Cron == | |
+ | The main advantage of using <code>Cron</code> 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 <code>crontab</code> file (using "'''<code>crontab -e</code>'''" command) of the current server user: | ||
<source lang="bash"> | <source lang="bash"> | ||
wget http://server_address/tools/cron.php -O /dev/null > /dev/null 2>&1 | wget http://server_address/tools/cron.php -O /dev/null > /dev/null 2>&1 | ||
</source> | </source> | ||
- | * '''<code>server_address</code>''' - | + | * '''<code>server_address</code>''' - complete URL your In-Portal website (ex. "<code>www.intechnic.com/test_project</code>"). |
- | + | In this case regular events won't be triggered when users are visiting the website, instead they will be triggered by calls from "'''<code>tools/cron.php</code>'''" 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 [[K4:Hooks|After Hook]] on the following Events: |
- | + | * '''<code>adm:OnStartup</code>''' - for execution before webpage displayed to the user; | |
+ | * '''<code>adm:OnBeforeShutdown</code>''' - 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 [[K4:Unit Configs#RegularEvents|RegularEvents]] section of [[K4:Unit Configs|Unit Configuration]] file: | ||
<source lang="php"> | <source lang="php"> | ||
'RegularEvents' => Array ( | 'RegularEvents' => Array ( | ||
Line 29: | Line 33: | ||
), | ), | ||
</source> | </source> | ||
- | + | Name of the key should '''unique''' among all other Regular Events through the system. | |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! Option name || Description |
|- | |- | ||
- | | {{ConfigProperty|EventName|string}} || | + | | {{ConfigProperty|EventName|string}} || Event name in current [[K4:Unit Configs|Unit Configuration]] file. |
|- | |- | ||
- | | {{ConfigProperty|RunInterval|int}} || | + | | {{ConfigProperty|RunInterval|int}} || Interval for triggering regular event (in seconds). |
|- | |- | ||
- | | {{ConfigProperty|Type|int, const}} || | + | | {{ConfigProperty|Type|int, const}} || Defines when regular event should be triggered in relation to the page output: |
- | * <code>reBEFORE</code> - | + | * <code>reBEFORE</code> - before page output; |
- | * <code>reAFTER</code> - | + | * <code>reAFTER</code> - after page output; |
|} | |} | ||
+ | |||
+ | [[en:{{FULLPAGENAME}}]] | ||
+ | [[ru:K4:Regular Events]] | ||
+ | |||
+ | Translated from: [http://guide.in-portal.org/rus/index.php?title=K4:Regular_Events&oldid=1074 revision 1074] |
Current revision
| ||
---|---|---|
Статьи в этой категории | ||
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:
|
Translated from: revision 1074