Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > Declaring a cron task

Declaring a cron task

To declare a task, you need to specify its name and frequency in seconds using the taches_generales_cron pipeline:

  1. function myplugin_general_cron_jobs($taches){
  2. $taches['nom'] = 24*3600; // once per day, every day
  3. }

Download

This task will be called at the appropriate time. The processes are placed in a file in the genie/ directory, with the same name as the (name.php) task and including a genie_name_dist() function.

The function is passed the date at which it last performed that task as an argument. It must return a number:

  • null, if the task has nothing to do
  • positive, if the task has been run
  • negative, if the task started but could not complete. This makes it possible to run tasks in batches (to avoid timeouts on PHP script executions because the processes run too long). In such cases, the negative number indicated corresponds to the number of seconds of interval before the next scheduled task run.

Example

This example is simple, originating from SPIP’s "maintenance" tasks in the genie/maintenance.php file, since it executes functions and always returns 1, indicating that the action has been run.

  1. // Various maintenance tasks
  2. function genie_maintenance_dist ($t) {
  3.  
  4. // (re)set .htaccess with deny from all
  5. // for the two nominated directories inaccessible through http
  6. include_spip('inc/acces');
  7. verifier_htaccess(_DIR_ETC);
  8. verifier_htaccess(_DIR_TMP);
  9.  
  10. // Confirm that neither table crashed
  11. if (!_request('reinstall'))
  12. verifier_crash_tables();
  13.  
  14. return 1;
  15. }

Download

  • Author :
  • Published :
  • Updated : 01/06/10
  • Translations : English, français