jcs:dampen() Function

Syntax

var $rc = jcs:dampen($tag, max, interval)

Description

Prevent the same operation from being repeatedly executed within a script. The dampen function returns true or false based on whether the number of calls to the jcs:dampen() function exceeds a max number of calls in the time interval interval. The function parameters include an arbitrary string, $tag, that is used to distinguish different calls to the jcs:dampen() function. This tag is stored in the /var/run directory on the device.

Parameters

Return Value

In the following example, if the jcs:dampen() function with the tag 'mytag1' is called less than three times in a 10-minute interval, the function returns true. If the function is called more than three times within 10 minutes, the function returns false.

if (jcs:dampen('mytag1', 3, 10)) {
     /* Code for situations when jcs:dampen() with */
     /* the tag 'mytag1' is called less than three times */
    /* within 10 minutes */
} else {
    /* Code for situations when jcs:dampen() with */
     /* the tag 'mytag1' exceeds the three call maximum */
    /* limit within 10 minutes */
}