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);
20 require_once("include/session.php");
21 require_once("include/datetime.php");
22 require_once('include/items.php');
23 require_once('include/bbcode.php');
24 require_once('include/socgraph.php');
26 load_config('config');
27 load_config('system');
29 // Don't check this stuff if the function is called by the poller
30 if (App::callstack() != "poller_run")
31 if (App::is_already_running('queue', 'include/queue.php', 540))
34 $a->set_baseurl(get_config('system','url'));
39 $queue_id = intval($argv[1]);
44 $deadservers = array();
45 $serverlist = array();
49 logger('queue: start');
51 // Handling the pubsubhubbub requests
52 proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
54 $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
56 // If we are using the worker we don't need a delivery interval
57 if (get_config("system", "worker"))
60 $r = q("select * from deliverq where 1");
63 logger('queue: deliverq');
64 proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
66 @time_sleep_until(microtime(true) + (float) $interval);
70 $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
71 INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
72 WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
75 logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
76 logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
78 q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
81 // For the first 12 hours we'll try to deliver every 15 minutes
82 // After that, we'll only attempt delivery once per hour.
84 $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`");
86 logger('queue: start for id '.$queue_id);
88 $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
98 call_hooks('queue_predeliver', $a, $r);
103 require_once('include/salmon.php');
104 require_once('include/diaspora.php');
106 foreach($r as $q_item) {
108 // queue_predeliver hooks may have changed the queue db details,
109 // so check again if this entry still needs processing
112 $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
114 elseif (get_config("system", "worker")) {
115 logger('Call queue for id '.$q_item['id']);
116 proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
119 $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
120 intval($q_item['id']));
126 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
127 intval($qi[0]['cid'])
130 remove_queue_item($q_item['id']);
133 if(in_array($c[0]['notify'],$deadguys)) {
134 logger('queue: skipping known dead url: ' . $c[0]['notify']);
135 update_queue_time($q_item['id']);
139 $server = poco_detect_server($c[0]['url']);
141 if (($server != "") AND !in_array($server, $serverlist)) {
142 logger("Check server ".$server." (".$c[0]["network"].")");
143 if (!poco_check_server($server, $c[0]["network"], true))
144 $deadservers[] = $server;
146 $serverlist[] = $server;
149 if (($server != "") AND in_array($server, $deadservers)) {
150 logger('queue: skipping known dead server: '.$server);
151 update_queue_time($q_item['id']);
155 $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
156 FROM `user` WHERE `uid` = %d LIMIT 1",
160 remove_queue_item($q_item['id']);
164 $data = $qi[0]['content'];
165 $public = $qi[0]['batch'];
171 switch($contact['network']) {
173 logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
174 $deliver_status = dfrn::deliver($owner,$contact,$data);
176 if($deliver_status == (-1)) {
177 update_queue_time($q_item['id']);
178 $deadguys[] = $contact['notify'];
180 remove_queue_item($q_item['id']);
183 case NETWORK_OSTATUS:
184 if($contact['notify']) {
185 logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
186 $deliver_status = slapper($owner,$contact['notify'],$data);
188 if($deliver_status == (-1)) {
189 update_queue_time($q_item['id']);
190 $deadguys[] = $contact['notify'];
192 remove_queue_item($q_item['id']);
195 case NETWORK_DIASPORA:
196 if($contact['notify']) {
197 logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
198 $deliver_status = diaspora::transmit($owner,$contact,$data,$public,true);
200 if($deliver_status == (-1)) {
201 update_queue_time($q_item['id']);
202 $deadguys[] = $contact['notify'];
204 remove_queue_item($q_item['id']);
210 $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
211 call_hooks('queue_deliver', $a, $params);
213 if($params['result'])
214 remove_queue_item($q_item['id']);
216 update_queue_time($q_item['id']);
221 logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
228 if (array_search(__file__,get_included_files())===0){
229 queue_run($_SERVER["argv"],$_SERVER["argc"]);