Cron
If you setup cron correctly as described in Cron special events will be triggered so you can register for these events from your own code.
L’exemple ci-dessous enregistre une fonction pour le cron quotidien.
function my_plugin_init() {
elgg_register_event_handler('cron', 'daily', 'my_plugin_cron_handler');
}
If timing is important in your cron event be advised that the functions are executed in order of registration. This could mean that your function may start (a lot) later then you may have expected. However the parameters provided in the event contain the original starting time of the cron, so you can always use that information.
function my_plugin_cron_handler(\Elgg\Event $event) {
$start_time = $event->getParam('time');
}
Intervalles personnalisés
Les développeurs de plugins peuvent configurer leurs propres intervalles personnalisés.
Avertissement
Il n’est PAS recommandé de faire cela, car les utilisateurs de votre plugin pourraient aussi avoir besoin de configurer votre intervalle personnalisé. Essayez de travailler avec les intervalles par défaut. Si vous avez seulement à effectuer une certaine tâche à 16:30, vous pouvez utiliser l’intervalle d’une demi-heure halfhour
et vérifier que date('G', $start_time) == 16
et date('i', $start_time) == 30
elgg_register_event_handler('cron:intervals', 'system', 'my_custom_cron_interval');
function my_custom_cron_interval(\Elgg\Event $event) {
$cron_intervals = $event->getValue();
// add custom interval
$cron_intervals['my_custom_interval'] = '30 16 * * *'; // every day at 16:30 hours
return $cron_intervals;
}
Voir aussi
Events has more information about events
Pour plus d’informations sur la définition des intervalles de cron pris en charge, voir la documentation PHP Scheduler