2 require_once("boot.php");
3 require_once('include/queue_fn.php');
4 require_once('include/dfrn.php');
6 function queue_run(&$argv, &$argc){
14 @include(".htconfig.php");
15 require_once("include/dba.php");
16 $db = new dba($db_host, $db_user, $db_pass, $db_data);
17 unset($db_host, $db_user, $db_pass, $db_data);
21 require_once("include/session.php");
22 require_once("include/datetime.php");
23 require_once('include/items.php');
24 require_once('include/bbcode.php');
25 require_once('include/socgraph.php');
27 load_config('config');
28 load_config('system');
30 // Don't check this stuff if the function is called by the poller
31 if (App::callstack() != "poller_run")
32 if (App::is_already_running('queue', 'include/queue.php', 540))
35 $a->set_baseurl(get_config('system','url'));
40 $queue_id = intval($argv[1]);
45 $deadservers = array();
46 $serverlist = array();
48 logger('queue: start');
50 // Handling the pubsubhubbub requests
51 proc_run('php','include/pubsubpublish.php');
53 $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
55 // If we are using the worker we don't need a delivery interval
56 if (get_config("system", "worker"))
59 $r = q("select * from deliverq where 1");
62 logger('queue: deliverq');
63 proc_run('php','include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
65 @time_sleep_until(microtime(true) + (float) $interval);
69 $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
70 INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
71 WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
74 logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
75 logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
77 q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
81 $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
87 // For the first 12 hours we'll try to deliver every 15 minutes
88 // After that, we'll only attempt delivery once per hour.
90 $r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
97 call_hooks('queue_predeliver', $a, $r);
102 require_once('include/salmon.php');
103 require_once('include/diaspora.php');
105 foreach($r as $q_item) {
107 // queue_predeliver hooks may have changed the queue db details,
108 // so check again if this entry still needs processing
111 $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
116 $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
117 intval($q_item['id'])
124 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
125 intval($qi[0]['cid'])
128 remove_queue_item($q_item['id']);
131 if(in_array($c[0]['notify'],$deadguys)) {
132 logger('queue: skipping known dead url: ' . $c[0]['notify']);
133 update_queue_time($q_item['id']);
137 $server = poco_detect_server($c[0]['url']);
139 if (($server != "") AND !in_array($server, $serverlist)) {
140 logger("Check server ".$server." (".$c[0]["network"].")");
141 if (!poco_check_server($server, $c[0]["network"], true))
142 $deadservers[] = $server;
144 $serverlist[] = $server;
147 if (($server != "") AND in_array($server, $deadservers)) {
148 logger('queue: skipping known dead server: '.$server);
149 update_queue_time($q_item['id']);
153 $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
154 FROM `user` WHERE `uid` = %d LIMIT 1",
158 remove_queue_item($q_item['id']);
162 $data = $qi[0]['content'];
163 $public = $qi[0]['batch'];
169 switch($contact['network']) {
171 logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
172 $deliver_status = dfrn::deliver($owner,$contact,$data);
174 if($deliver_status == (-1)) {
175 update_queue_time($q_item['id']);
176 $deadguys[] = $contact['notify'];
178 remove_queue_item($q_item['id']);
181 case NETWORK_OSTATUS:
182 if($contact['notify']) {
183 logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
184 $deliver_status = slapper($owner,$contact['notify'],$data);
186 if($deliver_status == (-1)) {
187 update_queue_time($q_item['id']);
188 $deadguys[] = $contact['notify'];
190 remove_queue_item($q_item['id']);
193 case NETWORK_DIASPORA:
194 if($contact['notify']) {
195 logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
196 $deliver_status = diaspora::transmit($owner,$contact,$data,$public,true);
198 if($deliver_status == (-1)) {
199 update_queue_time($q_item['id']);
200 $deadguys[] = $contact['notify'];
202 remove_queue_item($q_item['id']);
208 $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
209 call_hooks('queue_deliver', $a, $params);
211 if($params['result'])
212 remove_queue_item($q_item['id']);
214 update_queue_time($q_item['id']);
219 logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
226 if (array_search(__file__,get_included_files())===0){
227 queue_run($_SERVER["argv"],$_SERVER["argc"]);