- $lockpath = get_lockpath();
- if ($lockpath != '') {
- $pidfile = new pidfile($lockpath, 'poller');
- if($pidfile->is_already_running()) {
- logger("poller: Already running");
- if ($pidfile->running_time() > 9*60) {
- $pidfile->kill();
- logger("poller: killed stale process");
- // Calling a new instance
- proc_run('php','include/poller.php');
- }
- exit;
- }
- }
-
-
-
- $a->set_baseurl(get_config('system','url'));
-
- load_hooks();
-
- logger('poller: start');
-
- // run queue delivery process in the background
-
- proc_run('php',"include/queue.php");
-
- // run diaspora photo queue process in the background
-
- proc_run('php',"include/dsprphotoq.php");
-
- // expire any expired accounts
-
- q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
- AND `account_expires_on` != '0000-00-00 00:00:00'
- AND `account_expires_on` < UTC_TIMESTAMP() ");
-
- // delete user and contact records for recently removed accounts
-
- $r = q("SELECT * FROM `user` WHERE `account_removed` = 1 AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
- if ($r) {
- foreach($r as $user) {
- q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
- q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
- }
- }
-
- $abandon_days = intval(get_config('system','account_abandon_days'));
- if($abandon_days < 1)
- $abandon_days = 0;
-
- // Check OStatus conversations
- // Check only conversations with mentions (for a longer time)
- check_conversations(true);
-
- // Check every conversation
- check_conversations(false);
-
- // To-Do: Regenerate usage statistics
- // q("ANALYZE TABLE `item`");
-
- // once daily run birthday_updates and then expire in background
-
- $d1 = get_config('system','last_expire_day');
- $d2 = intval(datetime_convert('UTC','UTC','now','d'));
-
- if($d2 != intval($d1)) {
-
- update_contact_birthdays();
+ if(($argc <= 1) OR ($argv[1] != "no_cron")) {
+ // Run the cron job that calls all other jobs
+ proc_run("php","include/cron.php");
+
+ // Run the cronhooks job separately from cron for being able to use a different timing
+ proc_run("php","include/cronhooks.php");
+
+ // Cleaning dead processes
+ $r = q("SELECT DISTINCT(`pid`) FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
+ foreach($r AS $pid)
+ if (!posix_kill($pid["pid"], 0))
+ q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
+ intval($pid["pid"]));
+ else {
+ // To-Do: Kill long running processes
+ // But: Update processes (like the database update) mustn't be killed
+ }