aboutsummaryrefslogtreecommitdiffstats
path: root/include/poller.php
diff options
context:
space:
mode:
authorfabrixxm <fabrix.xm@gmail.com>2011-07-05 07:11:57 +0200
committerfabrixxm <fabrix.xm@gmail.com>2011-07-05 07:11:57 +0200
commit4e7a5dc56ebb8d99ed06b0b303c4ee24460ae6a8 (patch)
tree84184bd3aa80c896b8dceaf5a017297c7267f2cb /include/poller.php
parentcfd59f6ac8848c19a0c451c378d2b770cafcbef0 (diff)
parent2359783b9f6c0ec754c641453026712cf22e7cb6 (diff)
downloadvolse-hubzilla-4e7a5dc56ebb8d99ed06b0b303c4ee24460ae6a8.tar.gz
volse-hubzilla-4e7a5dc56ebb8d99ed06b0b303c4ee24460ae6a8.tar.bz2
volse-hubzilla-4e7a5dc56ebb8d99ed06b0b303c4ee24460ae6a8.zip
Merge branch 'dispy' of github.com:fabrixxm/friendika into dispy
Diffstat (limited to 'include/poller.php')
-rw-r--r--include/poller.php52
1 files changed, 45 insertions, 7 deletions
diff --git a/include/poller.php b/include/poller.php
index 7490bfa81..569eb59d1 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -2,6 +2,7 @@
require_once("boot.php");
+
function poller_run($argv, $argc){
global $a, $db;
@@ -17,13 +18,16 @@ function poller_run($argv, $argc){
};
- require_once('session.php');
- require_once('datetime.php');
- require_once('simplepie/simplepie.inc');
+ require_once('include/session.php');
+ require_once('include/datetime.php');
+ require_once('library/simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/email.php');
+ load_config('config');
+ load_config('system');
+
$a->set_baseurl(get_config('system','url'));
load_hooks();
@@ -44,18 +48,26 @@ function poller_run($argv, $argc){
proc_run('php','include/expire.php');
}
-
// clear old cache
q("DELETE FROM `cache` WHERE `updated` < '%s'",
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
$manual_id = 0;
+ $generation = 0;
$hub_update = false;
$force = false;
+ $restart = false;
if(($argc > 1) && ($argv[1] == 'force'))
$force = true;
+ if(($argc > 1) && ($argv[1] == 'restart')) {
+ $restart = true;
+ $generation = intval($argv[2]);
+ if(! $generation)
+ killme();
+ }
+
if(($argc > 1) && intval($argv[1])) {
$manual_id = intval($argv[1]);
$force = true;
@@ -67,7 +79,8 @@ function poller_run($argv, $argc){
$d = datetime_convert();
- call_hooks('cron', $d);
+ if(! $restart)
+ call_hooks('cron', $d);
$contacts = q("SELECT `id` FROM `contact`
@@ -151,6 +164,22 @@ function poller_run($argv, $argc){
continue;
}
+ // Check to see if we are running out of memory - if so spawn a new process and kill this one
+
+ $avail_memory = return_bytes(ini_get('memory_limit'));
+ $memused = memory_get_peak_usage(true);
+ if(intval($avail_memory)) {
+ if(($memused / $avail_memory) > 0.95) {
+ if($generation + 1 > 10) {
+ logger('poller: maximum number of spawns exceeded. Terminating.');
+ killme();
+ }
+ logger('poller: memory exceeded. ' . $memused . ' bytes used. Spawning new poll.');
+ proc_run('php', 'include/poller.php', 'restart', (string) $generation + 1);
+ killme();
+ }
+ }
+
$importer_uid = $contact['uid'];
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
@@ -281,13 +310,22 @@ function poller_run($argv, $argc){
// Upgrading DB fields from an older Friendika version
// Will only do this once per notify-enabled OStatus contact
+ // or if relationship changes
+
+ $stat_writeable = ((($contact['notify']) && ($contact['rel'] == REL_VIP || $contact['rel'] == REL_BUD)) ? 1 : 0);
- if(($contact['notify']) && (! $contact['writable'])) {
- q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d LIMIT 1",
+ if($stat_writeable != $contact['writable']) {
+ q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
+ intval($stat_writeable),
intval($contact['id'])
);
}
+ // Are we allowed to import from this person?
+
+ if($contact['rel'] == REL_VIP || $contact['blocked'] || $contact['readonly'])
+ continue;
+
$xml = fetch_url($contact['poll']);
}
elseif($contact['network'] === NETWORK_MAIL) {