The Time module provides time based code execution for XPSPL.
The Time Module has no runtime configuration options available.
Timeouts are functions executed once after a specific amount of time.
Timeouts are supported using the awake and xp_exhaust functions.
The below example demonstrates executing a timeout after 30 seconds.
<?php
// Import the time module.
xp_import('time');
// Define the exhaust rate of 1.
time\awake(30, xp_exhaust(1, function(){
echo '30 seconds just passed';
});
Intervals are functions executed continously after a specific amount of time.
The example below demonstrates an interval that runs every 30 seconds.
<?php
xp_import('time');
time\awake(30, function(){
echo '30 seconds passed';
});
The wait time period can be defined as seconds, milliseconds and microseconds.
Defining the instruction of time can be done by providing the $instruction to the awake function usign the time instruction constants.
The example below demonstrates executing timeouts in seconds, milliseconds and microseconds.
Warning
Microsecond precision CANNOT be guaranteed.
<?php
xp_import('time');
// SECONDS
time\awake(30, function(){
echo '30 seconds just passed';
}, TIME_SECONDS);
// MILLISECONDS
time\awake(1000, function(){
echo '1000 milliseconds just passed';
}, TIME_MILLISECONDS);
// SECONDS
time\awake(1000, function(){
echo '1000 microseconds just passed';
}, TIME_MICROSECONDS);
The CRON syntax is supported for executing signals based on the CRON syntax using the CRON api function.
The example below demonstrates executing a signal everyday at 12pm.
<?php
// CRON
time\CRON('12 * * * *', function(){
echo 'It is 12 oclock!';
});
All functions and classes are under the time namespace.
Wakes the system loop and runs the provided function.
| Parameters: |
|
|---|---|
| Return type: | array [signal, process] |
Wakes the system using the Unix CRON expressions.
If no priority is provided with the `$process` it is set to null.
| Parameters: |
|
|---|---|
| Return type: | array [signal, process] |