Merge pull request #987 from annando/master
Auto-killing processes, somce changed code in the plaintext function and speed issues in network
This commit is contained in:
commit
97e74f1570
|
@ -37,9 +37,15 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -50,11 +56,12 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
logger('cronhooks: start');
|
||||
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
call_hooks('cron', $d);
|
||||
|
||||
logger('cronhooks: end');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
|
||||
if(! function_exists('post_url')) {
|
||||
function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$a = get_app();
|
||||
|
@ -130,6 +129,8 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
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);
|
||||
|
@ -178,6 +179,8 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
$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
|
||||
|
@ -190,16 +193,18 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
}
|
||||
|
||||
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));
|
||||
|
||||
|
@ -209,6 +214,8 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
logger("post_url: end ".$url, LOGGER_DATA);
|
||||
|
||||
return($body);
|
||||
}}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ function onepoll_run(&$argv, &$argc){
|
|||
// 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;
|
||||
|
|
|
@ -28,5 +28,14 @@ class pidfile {
|
|||
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));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -9,6 +9,10 @@ function get_attached_data($body) {
|
|||
- 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)) {
|
||||
|
@ -38,40 +42,11 @@ function get_attached_data($body) {
|
|||
|
||||
}
|
||||
}
|
||||
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) {
|
||||
|
@ -125,6 +100,37 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false) {
|
|||
}
|
||||
}
|
||||
|
||||
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"] != "")
|
||||
|
|
|
@ -43,9 +43,15 @@ function poller_run(&$argv, &$argc){
|
|||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,9 +86,15 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -710,7 +710,7 @@ die("ss");
|
|||
);
|
||||
} 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user