require_once('library/Mobile_Detect/Mobile_Detect.php');
require_once('include/features.php');
require_once('include/identity.php');
-require_once('include/pidfile.php');
require_once('update.php');
require_once('include/dbstructure.php');
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) {
if (!function_exists("proc_open")) {
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.
- // This should prevent the forking of masses of workers.
- $cachekey = "app:proc_run:started";
- $result = Cache::get($cachekey);
- if (!is_null($result)) {
- if ((time() - $result) < 10) {
- return;
- }
+ // 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.
+ $cachekey = "app:proc_run:started";
+ $result = Cache::get($cachekey);
+ if (!is_null($result)) {
+ if ((time() - $result) < 10) {
+ return;
}
- // Set the timestamp of the last proc_run
- Cache::set($cachekey, time(), CACHE_MINUTE);
-
- $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
}
+ // Set the timestamp of the last proc_run
+ Cache::set($cachekey, time(), CACHE_MINUTE);
+
+ 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
$args[] = $this->get_baseurl();
* @brief Wrap calls to proc_close(proc_open()) and call hook
* 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
- * e.g.: proc_run("ls","-la","/tmp");
* 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);
*
if (!$arr['run_cmd'] OR !count($args))
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;
$dont_fork = get_config("system", "worker_dont_fork");
return;
// 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);
}
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
*
+++ /dev/null
-<?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));
- }
-}
-?>
$itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
$itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 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'])) : '');
$basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
$singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
set_config('system','itemcache', $itemcache);
set_config('system','itemcache_duration', $itemcache_duration);
set_config('system','max_comments', $max_comments);
- set_config('system','lockpath', $lockpath);
set_config('system','temppath', $temppath);
set_config('system','basepath', $basepath);
set_config('system','proxy_disabled', $proxy_disabled);
// Automatically create temporary paths
get_temppath();
- get_lockpath();
get_itemcachepath();
//echo "<pre>"; var_dump($lang_choices); die("</pre>");
'$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.")),
'$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.")),
'$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.")),