fix #136, annoying warnings when is enabled open_basedir or disabled url fopen
[elgg.git] / cron.php
blob5aec7f120ad096ddac2052085116c5f28e204504
1 <?php
3 // very basic cron functionality.
4 // later this will go through /mod
5 // and things like auth plugins
6 // but we don't have those yet, so...
8 $starttime = microtime();
10 require_once(dirname(__FILE__)."/includes.php");
12 $timenow = time();
14 mtrace("<pre>");
15 mtrace("Server Time: ".date('r',$timenow)."\n\n");
17 $lastcron = $CFG->lastcron;
18 if (empty($lastcron)) {
19 $lastcron = 0;
22 // we only want to do this once a day because it could take awhile...
23 if ($timenow - (60*60*24) > $lastcron) {
24 mtrace('Cleaning up old incoming files... ','');
25 // clean up the lms incoming files
26 delete_records_select('files_incoming','intentiondate < ?',array(time()-60*60*24));
28 $dirtocheck = $CFG->dataroot.'temp/lms/';
29 $cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf";
30 exec($cmd);
32 $dirtocheck = $CFG->dataroot.'lms/incoming';
33 // this is not going to work unless this script is running as either the owner of these files
34 // or root.
35 $cmd = "find $dirtocheck -type d -cmin 1440 -print0 | xargs -0 -r rm -rf";
36 exec($cmd);
38 mtrace('done');
41 // module cron
42 if ($mods = get_list_of_plugins()) {
43 foreach ($mods as $mod) {
44 $libfile = $CFG->dirroot.'mod/'.$mod.'/lib.php';
45 if (!file_exists($libfile)) {
46 continue;
48 require_once($libfile);
49 $cronfunction = $mod.'_cron';
50 if (!function_exists($cronfunction)) {
51 continue;
53 // each module is responsible for checking their last runtime and not running again if it's too soon.
54 mtrace('Running cron for '.$mod.'...','');
55 $cronfunction();
56 mtrace('Done');
61 if (!set_config('lastcron',$timenow)) {
62 mtrace('Could not update last cron time to now!');
65 mtrace("Cron script completed correctly");
67 $difftime = microtime_diff($starttime, microtime());
68 mtrace("Execution took ".$difftime." seconds");