]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
move account/update_profile_image to section with general API's
[friendica.git] / boot.php
index 05588b8d2c419cc40eb360f41da0960e6db7bb3c..99af7d3778c1012e3312647deac47eaf63388224 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.2-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1218      );
+define ( 'DB_UPDATE_VERSION',      1221      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -218,6 +218,20 @@ define ( 'CP_USERS_ON_SERVER',     0 );
 define ( 'CP_GLOBAL_COMMUNITY',    1 );
 /** @}*/
 
+/**
+ * @name Protocols
+ *
+ * Different protocols that we are storing
+ * @{
+ */
+define('PROTOCOL_UNKNOWN',         0);
+define('PROTOCOL_DFRN',            1);
+define('PROTOCOL_DIASPORA',        2);
+define('PROTOCOL_OSTATUS_SALMON',  3);
+define('PROTOCOL_OSTATUS_FEED',    4);
+define('PROTOCOL_GS_CONVERSATION', 5);
+/** @}*/
+
 /**
  * @name Network
  *
@@ -354,6 +368,7 @@ define ( 'NAMESPACE_FEED',            'http://schemas.google.com/g/2010#updates-
 define ( 'NAMESPACE_OSTATUS',         'http://ostatus.org/schema/1.0' );
 define ( 'NAMESPACE_STATUSNET',       'http://status.net/schema/api/1/' );
 define ( 'NAMESPACE_ATOM1',           'http://www.w3.org/2005/Atom' );
+define ( 'NAMESPACE_MASTODON',        'http://mastodon.social/schema/1.0' );
 /* @}*/
 
 /**
@@ -1306,6 +1321,45 @@ class App {
                return false;
        }
 
+       /**
+        * @brief Checks if the minimal memory is reached
+        *
+        * @return bool Is the memory limit reached?
+        */
+       public function min_memory_reached() {
+               $min_memory = Config::get('system', 'min_memory', 0);
+               if ($min_memory == 0) {
+                       return false;
+               }
+
+               if (!is_readable("/proc/meminfo")) {
+                       return false;
+               }
+
+               $memdata = explode("\n", file_get_contents('/proc/meminfo'));
+
+               $meminfo = array();
+               foreach ($memdata as $line) {
+                       list($key, $val) = explode(":", $line);
+                       $meminfo[$key] = (int)trim(str_replace("kB", "", $val));
+                       $meminfo[$key] = (int)($meminfo[$key] / 1024);
+               }
+
+               if (!isset($meminfo['MemAvailable']) OR !isset($meminfo['MemFree'])) {
+                       return false;
+               }
+
+               $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
+
+               $reached = ($free < $min_memory);
+
+               if ($reached) {
+                       logger('Minimal memory reached: '.$free.'/'.$meminfo['MemTotal'].' - limit '.$min_memory, LOGGER_DEBUG);
+               }
+
+               return $reached;
+       }
+
        /**
         * @brief Checks if the maximum load is reached
         *
@@ -1366,12 +1420,20 @@ class App {
 
                $cmdline = implode($args, " ");
 
+               if ($this->min_memory_reached()) {
+                       return;
+               }
+
                if (get_config('system', 'proc_windows')) {
-                       proc_close(proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__)));
+                       $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));
                } else {
-                       proc_close(proc_open($cmdline . " &", array(), $foo, dirname(__FILE__)));
+                       $resource = proc_open($cmdline . " &", array(), $foo, dirname(__FILE__));
                }
-
+               if (!is_resource($resource)) {
+                       logger('We got no resource for command '.$cmdline, LOGGER_DEBUG);
+                       return;
+               }
+               proc_close($resource);
        }
 
        /**