1
1
Fork 0

Removed some more unneeded stuff

This commit is contained in:
Michael 2017-02-27 06:27:22 +00:00
parent 46308fa1ef
commit 99fb15037b
5 changed files with 15 additions and 134 deletions

View file

@ -32,7 +32,6 @@ require_once('include/cache.php');
require_once('library/Mobile_Detect/Mobile_Detect.php'); require_once('library/Mobile_Detect/Mobile_Detect.php');
require_once('include/features.php'); require_once('include/features.php');
require_once('include/identity.php'); require_once('include/identity.php');
require_once('include/pidfile.php');
require_once('update.php'); require_once('update.php');
require_once('include/dbstructure.php'); require_once('include/dbstructure.php');
@ -1346,44 +1345,12 @@ class App {
return false; return false;
} }
/**
* @brief Checks if the process is already running
*
* @param string $taskname The name of the task that will be used for the name of the lockfile
* @param string $task The path and name of the php script
* @param int $timeout The timeout after which a task should be killed
*
* @return bool Is the process running?
*/
function is_already_running($taskname, $task = "", $timeout = 540) {
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, $taskname);
if ($pidfile->is_already_running()) {
logger("Already running");
if ($pidfile->running_time() > $timeout) {
$pidfile->kill();
logger("killed stale process");
// Calling a new instance
if ($task != "")
proc_run(PRIORITY_MEDIUM, $task);
}
return true;
}
}
return false;
}
function proc_run($args) { function proc_run($args) {
if (!function_exists("proc_open")) { if (!function_exists("proc_open")) {
return; return;
} }
// Add the php path if it is a php call
if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) {
// If the last worker fork was less than 10 seconds before then don't fork another one. // If the last worker fork was less than 10 seconds before then don't fork another one.
// This should prevent the forking of masses of workers. // This should prevent the forking of masses of workers.
$cachekey = "app:proc_run:started"; $cachekey = "app:proc_run:started";
@ -1396,8 +1363,7 @@ class App {
// Set the timestamp of the last proc_run // Set the timestamp of the last proc_run
Cache::set($cachekey, time(), CACHE_MINUTE); Cache::set($cachekey, time(), CACHE_MINUTE);
$args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); array_unshift($args, ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
}
// add baseurl to args. cli scripts can't construct it // add baseurl to args. cli scripts can't construct it
$args[] = $this->get_baseurl(); $args[] = $this->get_baseurl();
@ -1950,10 +1916,9 @@ function get_max_import_size() {
* @brief Wrap calls to proc_close(proc_open()) and call hook * @brief Wrap calls to proc_close(proc_open()) and call hook
* so plugins can take part in process :) * so plugins can take part in process :)
* *
* @param (string|integer|array) $cmd program to run, priority or parameter array * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
* *
* next args are passed as $cmd command line * next args are passed as $cmd command line
* e.g.: proc_run("ls","-la","/tmp");
* or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); * or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
* or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id); * or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id);
* *
@ -1998,12 +1963,6 @@ function proc_run($cmd){
if (!$arr['run_cmd'] OR !count($args)) if (!$arr['run_cmd'] OR !count($args))
return; return;
/// @todo I guess we can remove it, since we don't call it with something different
if (is_string($run_parameter) AND ($run_parameter != 'php')) {
$a->proc_run($args);
return;
}
$priority = PRIORITY_MEDIUM; $priority = PRIORITY_MEDIUM;
$dont_fork = get_config("system", "worker_dont_fork"); $dont_fork = get_config("system", "worker_dont_fork");
@ -2051,7 +2010,7 @@ function proc_run($cmd){
return; return;
// Now call the poller to execute the jobs that we just added to the queue // Now call the poller to execute the jobs that we just added to the queue
$args = array("php", "include/poller.php", "no_cron"); $args = array("include/poller.php", "no_cron");
$a->proc_run($args); $a->proc_run($args);
} }
@ -2385,38 +2344,6 @@ function get_itemcachepath() {
return ""; return "";
} }
function get_lockpath() {
$lockpath = get_config('system','lockpath');
if (($lockpath != "") AND App::directory_usable($lockpath)) {
// We have a lock path and it is usable
return $lockpath;
}
// We don't have a working preconfigured lock path, so we take the temp path.
$temppath = get_temppath();
if ($temppath != "") {
// To avoid any interferences with other systems we create our own directory
$lockpath = $temppath."/lock";
if (!is_dir($lockpath)) {
mkdir($lockpath);
}
if (App::directory_usable($lockpath)) {
// The new path is usable, we are happy
set_config("system", "lockpath", $lockpath);
return $lockpath;
} else {
// We can't create a subdirectory, strange.
// But the directory seems to work, so we use it but don't store it.
return $temppath;
}
}
// Reaching this point means that the operating system is configured badly.
return "";
}
/** /**
* @brief Returns the path where spool files are stored * @brief Returns the path where spool files are stored
* *

View file

@ -1,41 +0,0 @@
<?php
class pidfile {
private $_file;
private $_running;
public function __construct($dir, $name) {
$this->_file = "$dir/$name.pid";
if (file_exists($this->_file)) {
$pid = trim(@file_get_contents($this->_file));
if (($pid != "") AND posix_kill($pid, 0)) {
$this->_running = true;
}
}
if (! $this->_running) {
$pid = getmypid();
file_put_contents($this->_file, $pid);
}
}
public function __destruct() {
if ((! $this->_running) && file_exists($this->_file)) {
@unlink($this->_file);
}
}
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));
}
}
?>

View file

@ -458,7 +458,7 @@ function poller_too_much_workers() {
// Are there fewer workers running as possible? Then fork a new one. // Are there fewer workers running as possible? Then fork a new one.
if (!Config::get("system", "worker_dont_fork") AND ($queues > ($active + 1)) AND ($entries > 1)) { if (!Config::get("system", "worker_dont_fork") AND ($queues > ($active + 1)) AND ($entries > 1)) {
logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG); logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
$args = array("php", "include/poller.php", "no_cron"); $args = array("include/poller.php", "no_cron");
$a = get_app(); $a = get_app();
$a->proc_run($args); $a->proc_run($args);
} }
@ -604,7 +604,7 @@ function call_worker_if_idle() {
logger('Call poller', LOGGER_DEBUG); logger('Call poller', LOGGER_DEBUG);
$args = array("php", "include/poller.php", "no_cron"); $args = array("include/poller.php", "no_cron");
$a = get_app(); $a = get_app();
$a->proc_run($args); $a->proc_run($args);
return; return;

View file

@ -650,7 +650,6 @@ function admin_page_site_post(App $a) {
$itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : ''); $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
$itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0); $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
$max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0); $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0);
$lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : '');
$temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : ''); $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
$basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : ''); $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
$singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : ''); $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
@ -801,7 +800,6 @@ function admin_page_site_post(App $a) {
set_config('system','itemcache', $itemcache); set_config('system','itemcache', $itemcache);
set_config('system','itemcache_duration', $itemcache_duration); set_config('system','itemcache_duration', $itemcache_duration);
set_config('system','max_comments', $max_comments); set_config('system','max_comments', $max_comments);
set_config('system','lockpath', $lockpath);
set_config('system','temppath', $temppath); set_config('system','temppath', $temppath);
set_config('system','basepath', $basepath); set_config('system','basepath', $basepath);
set_config('system','proxy_disabled', $proxy_disabled); set_config('system','proxy_disabled', $proxy_disabled);
@ -925,7 +923,6 @@ function admin_page_site(App $a) {
// Automatically create temporary paths // Automatically create temporary paths
get_temppath(); get_temppath();
get_lockpath();
get_itemcachepath(); get_itemcachepath();
//echo "<pre>"; var_dump($lang_choices); die("</pre>"); //echo "<pre>"; var_dump($lang_choices); die("</pre>");
@ -1044,7 +1041,6 @@ function admin_page_site(App $a) {
'$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")), '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")),
'$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")), '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")),
'$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")), '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")),
'$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), t("The lock file is used to avoid multiple pollers at one time. Only define a folder here.")),
'$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")), '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")),
'$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot.")), '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot.")),
'$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")), '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")),

View file

@ -125,7 +125,6 @@
{{include file="field_input.tpl" field=$optimize_max_tablesize}} {{include file="field_input.tpl" field=$optimize_max_tablesize}}
{{include file="field_input.tpl" field=$optimize_fragmentation}} {{include file="field_input.tpl" field=$optimize_fragmentation}}
{{include file="field_input.tpl" field=$abandon_days}} {{include file="field_input.tpl" field=$abandon_days}}
{{include file="field_input.tpl" field=$lockpath}}
{{include file="field_input.tpl" field=$temppath}} {{include file="field_input.tpl" field=$temppath}}
{{include file="field_input.tpl" field=$basepath}} {{include file="field_input.tpl" field=$basepath}}
{{include file="field_checkbox.tpl" field=$suppress_language}} {{include file="field_checkbox.tpl" field=$suppress_language}}