]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Works now
[friendica.git] / src / App.php
index 15538e88da00f4ac2f925c9c9cbc07038d8ff105..ec03829933d8478ea81b6c53ecfe6b1d7ccfadf7 100644 (file)
@@ -5,6 +5,13 @@ namespace Friendica;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 
+use Cache;
+use dbm;
+
+use Detection\MobileDetect;
+
+use Exception;
+
 /**
  *
  * class: App
@@ -93,6 +100,7 @@ class App {
         */
        public $template_engine_instance = array();
        public $process_id;
+       public $queue;
        private $ldelim = array(
                'internal' => '',
                'smarty3' => '{{'
@@ -192,7 +200,7 @@ class App {
                }
 
                if (! static::directory_usable($basepath, false)) {
-                       throw new \Exception('Basepath ' . $basepath . ' isn\'t usable.');
+                       throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
                }
 
                $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
@@ -276,7 +284,7 @@ class App {
                $this->pager['total'] = 0;
 
                // Detect mobile devices
-               $mobile_detect = new \Mobile_Detect();
+               $mobile_detect = new MobileDetect();
                $this->is_mobile = $mobile_detect->isMobile();
                $this->is_tablet = $mobile_detect->isTablet();
 
@@ -319,7 +327,27 @@ class App {
                        $basepath = $_SERVER['PWD'];
                }
 
-               return $basepath;
+               return self::realpath($basepath);
+       }
+
+       /**
+        * @brief Returns a normalized file path
+        *
+        * This is a wrapper for the "realpath" function.
+        * That function cannot detect the real path when some folders aren't readable.
+        * Since this could happen with some hosters we need to handle this.
+        *
+        * @param string $path The path that is about to be normalized
+        * @return string normalized path - when possible
+        */
+       public static function realpath($path) {
+               $normalized = realpath($path);
+
+               if (!is_bool($normalized)) {
+                       return $normalized;
+               } else {
+                       return $path;
+               }
        }
 
        function get_scheme() {
@@ -399,7 +427,7 @@ class App {
                                $this->hostname = Config::get('config', 'hostname');
                        }
 
-                       if (!isset($this->hostname) OR ( $this->hostname == '')) {
+                       if (!isset($this->hostname) || ( $this->hostname == '')) {
                                $this->hostname = $hostname;
                        }
                }
@@ -687,7 +715,7 @@ class App {
                q('START TRANSACTION');
 
                $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
-               if (!\dbm::is_result($r)) {
+               if (!dbm::is_result($r)) {
                        q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));
                }
                q('COMMIT');
@@ -700,7 +728,7 @@ class App {
                q('START TRANSACTION');
 
                $r = q('SELECT `pid` FROM `process`');
-               if (\dbm::is_result($r)) {
+               if (dbm::is_result($r)) {
                        foreach ($r AS $process) {
                                if (!posix_kill($process['pid'], 0)) {
                                        q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));
@@ -722,8 +750,8 @@ class App {
         *
         * @return string
         */
-       function callstack() {
-               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
+       function callstack($depth = 4) {
+               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2);
 
                // We remove the first two items from the list since they contain data that we don't need.
                array_shift($trace);
@@ -790,6 +818,8 @@ class App {
         * @return bool Is the limit reached?
         */
        function max_processes_reached() {
+               // Deactivated, needs more investigating if this check really makes sense
+               return false;
 
                if ($this->is_backend()) {
                        $process = 'backend';
@@ -805,7 +835,7 @@ class App {
                        }
                }
 
-               $processlist = \dbm::processlist();
+               $processlist = dbm::processlist();
                if ($processlist['list'] != '') {
                        logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
 
@@ -841,7 +871,7 @@ class App {
                        $meminfo[$key] = (int) ($meminfo[$key] / 1024);
                }
 
-               if (!isset($meminfo['MemAvailable']) OR ! isset($meminfo['MemFree'])) {
+               if (!isset($meminfo['MemAvailable']) || ! isset($meminfo['MemFree'])) {
                        return false;
                }
 
@@ -893,17 +923,17 @@ class App {
                        return;
                }
 
-               // 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 2 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);
+               $result = Cache::get($cachekey);
 
-               if (!is_null($result) AND ( time() - $result) < 10) {
+               if (!is_null($result) && ( time() - $result) < 2) {
                        return;
                }
 
                // Set the timestamp of the last proc_run
-               \Cache::set($cachekey, time(), CACHE_MINUTE);
+               Cache::set($cachekey, time(), CACHE_MINUTE);
 
                array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
 
@@ -940,7 +970,7 @@ class App {
         * @return string system username
         */
        static function systemuser() {
-               if (!function_exists('posix_getpwuid') OR ! function_exists('posix_geteuid')) {
+               if (!function_exists('posix_getpwuid') || ! function_exists('posix_geteuid')) {
                        return '';
                }
 
@@ -971,7 +1001,7 @@ class App {
                        logger('Path "' . $directory . '" is not a directory for user ' . self::systemuser(), LOGGER_DEBUG);
                        return false;
                }
-               if ($check_writable AND !is_writable($directory)) {
+               if ($check_writable && !is_writable($directory)) {
                        logger('Path "' . $directory . '" is not writable for user ' . self::systemuser(), LOGGER_DEBUG);
                        return false;
                }