streams/include/poller.php

147 lines
3.3 KiB
PHP
Raw Normal View History

2010-07-19 03:49:54 +00:00
<?php
2011-04-16 06:40:43 +00:00
2012-12-31 00:14:29 +00:00
require_once('boot.php');
require_once('include/cli_startup.php');
function poller_run($argv, $argc){
2010-08-17 03:47:40 +00:00
2012-12-31 00:14:29 +00:00
cli_startup();
2011-04-16 06:40:43 +00:00
2012-12-31 00:14:29 +00:00
$a = get_app();
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
return;
}
}
2010-11-26 02:31:33 +00:00
logger('poller: start');
2010-11-26 02:22:54 +00:00
// run queue delivery process in the background
2010-11-22 23:30:52 +00:00
2011-02-23 23:16:12 +00:00
proc_run('php',"include/queue.php");
2011-01-31 16:16:35 +00:00
2011-09-26 12:43:22 +00:00
// expire any expired accounts
q("UPDATE account
SET account_flags = account_flags | %d
where not account_flags & %d
and account_expires != '0000-00-00 00:00:00'
and account_expires < UTC_TIMESTAMP() ",
intval(ACCOUNT_EXPIRED),
intval(ACCOUNT_EXPIRED)
);
2011-09-26 12:43:22 +00:00
2011-09-30 04:20:19 +00:00
$abandon_days = intval(get_config('system','account_abandon_days'));
if($abandon_days < 1)
$abandon_days = 0;
2011-10-14 07:20:37 +00:00
// once daily run birthday_updates and then expire in background
2011-03-16 00:31:49 +00:00
$d1 = get_config('system','last_expire_day');
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
if($d2 != intval($d1)) {
2011-10-14 07:20:37 +00:00
2012-12-31 06:56:52 +00:00
// update_suggestions();
2011-03-16 00:31:49 +00:00
set_config('system','last_expire_day',$d2);
proc_run('php','include/expire.php');
}
$manual_id = 0;
$generation = 0;
2012-08-31 01:47:07 +00:00
$force = false;
$restart = false;
2012-12-31 00:14:29 +00:00
if((argc() > 1) && (argv(1) == 'force'))
2010-11-05 03:47:44 +00:00
$force = true;
2012-12-31 00:14:29 +00:00
if((argc() > 1) && (argv(1) == 'restart')) {
$restart = true;
2012-12-31 00:14:29 +00:00
$generation = intval(argv(2));
if(! $generation)
killme();
}
2012-12-31 00:14:29 +00:00
if((argc() > 1) && intval(argv(1))) {
$manual_id = intval(argv(1));
$force = true;
2011-01-24 04:09:34 +00:00
}
$interval = intval(get_config('system','poll_interval'));
if(! $interval)
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
2012-12-31 00:14:29 +00:00
$sql_extra = (($manual_id) ? " AND abook_id = $manual_id " : "");
2011-01-24 04:09:34 +00:00
2011-04-26 11:39:27 +00:00
reload_plugins();
2011-03-09 10:12:32 +00:00
$d = datetime_convert();
2011-04-26 11:39:27 +00:00
2012-12-31 00:14:29 +00:00
//TODO check to see if there are any cronhooks before wasting a process
if(! $restart)
proc_run('php','include/cronhooks.php');
2011-03-09 10:12:32 +00:00
2011-08-24 01:17:35 +00:00
// Only poll from those with suitable relationships,
// and which have a polling address and ignore Diaspora since
// we are unable to match those posts with a Diaspora GUID and prevent duplicates.
2011-09-30 04:20:19 +00:00
$abandon_sql = (($abandon_days)
2012-12-31 00:14:29 +00:00
? sprintf(" AND account_lastlog > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
2011-09-30 04:20:19 +00:00
: ''
);
2012-12-31 00:14:29 +00:00
$contacts = q("SELECT abook_id, abook_updated, abook_closeness, abook_channel
2012-12-31 07:51:39 +00:00
FROM abook LEFT JOIN account on abook_account = account_id where 1
2011-01-24 04:09:34 +00:00
$sql_extra
2012-12-31 07:51:39 +00:00
AND (( abook_flags = %d ) OR ( abook_flags = %d ))
AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY RAND()",
intval(ABOOK_FLAG_HIDDEN),
intval(0),
intval(ACCOUNT_OK),
intval(ACCOUNT_UNVERIFIED) // FIXME
2012-12-31 00:14:29 +00:00
);
2010-07-19 03:49:54 +00:00
2012-12-31 00:14:29 +00:00
if(! $contacts) {
return;
}
2010-07-19 03:49:54 +00:00
2012-12-31 00:14:29 +00:00
foreach($contacts as $contact) {
$update = false;
$t = $contact['abook_updated'];
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
$update = true;
if((! $update) && (! $force))
continue;
proc_run('php','include/onepoll.php',$contact['abook_id']);
if($interval)
@time_sleep_until(microtime(true) + (float) $interval);
}
2011-04-16 15:45:08 +00:00
return;
}
2010-07-19 03:49:54 +00:00
if (array_search(__file__,get_included_files())===0){
poller_run($argv,$argc);
killme();
}