Auto-killing processes, somce changed code in the plaintext function and speed issues in network
$lockpath = get_config('system','lockpath');
if ($lockpath != '') {
- $pidfile = new pidfile($lockpath, 'cron.lck');
+ $pidfile = new pidfile($lockpath, 'cronhooks');
if($pidfile->is_already_running()) {
logger("cronhooks: Already running");
+ if ($pidfile->running_time() > 9*60) {
+ $pidfile->kill();
+ logger("cronhooks: killed stale process");
+ // Calling a new instance
+ proc_run('php','include/cronhooks.php');
+ }
exit;
}
}
logger('cronhooks: start');
-
$d = datetime_convert();
call_hooks('cron', $d);
+ logger('cronhooks: end');
+
return;
}
if(! function_exists('post_url')) {
function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
-
$stamp1 = microtime(true);
$a = get_app();
if(($redirects > 8) || (! $ch))
return false;
+ logger("post_url: start ".$url, LOGGER_DATA);
+
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1);
$curl_info = curl_getinfo($ch);
$http_code = $curl_info['http_code'];
+ logger("post_url: result ".$http_code." - ".$url, LOGGER_DATA);
+
$header = '';
// Pull out multiple headers, e.g. proxy and continuation headers
}
if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
- $matches = array();
- preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $newurl = trim(array_pop($matches));
if(strpos($newurl,'/') === 0)
$newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl;
- if (filter_var($newurl, FILTER_VALIDATE_URL)) {
- $redirects++;
- return fetch_url($newurl,false,$redirects,$timeout);
- }
- }
+ if (filter_var($newurl, FILTER_VALIDATE_URL)) {
+ $redirects++;
+ logger("post_url: redirect ".$url." to ".$newurl);
+ return post_url($newurl,$params, $headers, $redirects, $timeout);
+ //return fetch_url($newurl,false,$redirects,$timeout);
+ }
+ }
$a->set_curl_code($http_code);
$body = substr($s,strlen($header));
$a->save_timestamp($stamp1, "network");
+ logger("post_url: end ".$url, LOGGER_DATA);
+
return($body);
}}
// Test
$lockpath = get_config('system','lockpath');
if ($lockpath != '') {
- $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id.'.lck');
+ $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
if($pidfile->is_already_running()) {
logger("onepoll: Already running for contact ".$contact_id);
exit;
public function is_already_running() {
return $this->_running;
}
+
+ public function running_time() {
+ return(time() - filectime($this->_file));
+ }
+
+ public function kill() {
+ if (file_exists($this->_file))
+ return(posix_kill(file_get_contents($this->_file), SIGTERM));
+ }
}
?>
- description:
- (thumbnail)
*/
+
+ // Simplify image codes
+ $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
+
$post = array();
if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism",$body, $attached, PREG_SET_ORDER)) {
}
}
- return($post);
-}
-
-function shortenmsg($msg, $limit) {
- $lines = explode("\n", $msg);
- $msg = "";
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- foreach ($lines AS $row=>$line) {
- if (strlen(trim($msg."\n".$line)) <= $limit)
- $msg = trim($msg."\n".$line);
- // Is the new message empty by now or is it a reshared message?
- elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle)))
- $msg = substr(substr(trim($msg."\n".$line), 0, $limit), 0, -3)."...";
- else
- break;
- }
- return($msg);
-}
-
-function plaintext($a, $b, $limit = 0, $includedlinks = false) {
- require_once("include/bbcode.php");
- require_once("include/html2plain.php");
- require_once("mod/parse_url.php");
- require_once("include/network.php");
-
- // Simplify image codes
- $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $b["body"]);
-
- // At first look at data that is attached via "type-..." stuff
- // This will hopefully replaced with a dedicated bbcode later
- $post = get_attached_data($body);
// if nothing is found, it maybe having an image.
if (!isset($post["type"])) {
+ require_once("mod/parse_url.php");
+
$URLSearchString = "^\[\]";
if (preg_match_all("(\[url=([$URLSearchString]*)\]\s*\[img\]([$URLSearchString]*)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
if (count($pictures) == 1) {
}
}
+ return($post);
+}
+
+function shortenmsg($msg, $limit, $twitter = false) {
+ // To-Do:
+ // For Twitter URLs aren't shortened, but they have to be calculated as if.
+
+ $lines = explode("\n", $msg);
+ $msg = "";
+ $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
+ foreach ($lines AS $row=>$line) {
+ if (strlen(trim($msg."\n".$line)) <= $limit)
+ $msg = trim($msg."\n".$line);
+ // Is the new message empty by now or is it a reshared message?
+ elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle)))
+ $msg = substr(substr(trim($msg."\n".$line), 0, $limit), 0, -3)."...";
+ else
+ break;
+ }
+ return($msg);
+}
+
+function plaintext($a, $b, $limit = 0, $includedlinks = false) {
+ require_once("include/bbcode.php");
+ require_once("include/html2plain.php");
+ require_once("include/network.php");
+
+ // At first look at data that is attached via "type-..." stuff
+ // This will hopefully replaced with a dedicated bbcode later
+ $post = get_attached_data($b["body"]);
+
if (($b["title"] != "") AND ($post["text"] != ""))
$post["text"] = trim($b["title"]."\n\n".$post["text"]);
elseif ($b["title"] != "")
$lockpath = get_config('system','lockpath');
if ($lockpath != '') {
- $pidfile = new pidfile($lockpath, 'poller.lck');
+ $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;
}
}
$lockpath = get_config('system','lockpath');
if ($lockpath != '') {
- $pidfile = new pidfile($lockpath, 'queue.lck');
+ $pidfile = new pidfile($lockpath, 'queue');
if($pidfile->is_already_running()) {
logger("queue: Already running");
+ if ($pidfile->running_time() > 9*60) {
+ $pidfile->kill();
+ logger("queue: killed stale process");
+ // Calling a new instance
+ proc_run('php',"include/queue.php");
+ }
return;
}
}
);
} else {
$r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
- FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
+ FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0
AND `thread`.`moderated` = 0