]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
fix some method names (camelcase) in Probe.php and Lock.php
[friendica.git] / boot.php
index 5417e0fa23646708d77ac1a252f2470fc1593bb6..9c0ef1d08033327c421e247a906cb15f8e0edfdc 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -22,6 +22,7 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a
 
 use Friendica\App;
 use Friendica\Core\Config;
+use Friendica\Util\Lock;
 
 require_once 'include/config.php';
 require_once 'include/network.php';
@@ -41,7 +42,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.3-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1229      );
+define ( 'DB_UPDATE_VERSION',      1233      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -1069,6 +1070,7 @@ function proc_run($cmd) {
 
        $priority = PRIORITY_MEDIUM;
        $dont_fork = get_config("system", "worker_dont_fork");
+       $created = datetime_convert();
 
        if (is_int($run_parameter)) {
                $priority = $run_parameter;
@@ -1076,6 +1078,9 @@ function proc_run($cmd) {
                if (isset($run_parameter['priority'])) {
                        $priority = $run_parameter['priority'];
                }
+               if (isset($run_parameter['created'])) {
+                       $created = $run_parameter['created'];
+               }
                if (isset($run_parameter['dont_fork'])) {
                        $dont_fork = $run_parameter['dont_fork'];
                }
@@ -1085,10 +1090,10 @@ function proc_run($cmd) {
        array_shift($argv);
 
        $parameters = json_encode($argv);
-       $found = dba::select('workerqueue', array('id'), array('parameter' => $parameters), array('limit' => 1));
+       $found = dba::select('workerqueue', array('id'), array('parameter' => $parameters, 'done' => false), array('limit' => 1));
 
        if (!dbm::is_result($found)) {
-               dba::insert('workerqueue', array('parameter' => $parameters, 'created' => datetime_convert(), 'priority' => $priority));
+               dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
        }
 
        // Should we quit and wait for the poller to be called as a cronjob?
@@ -1096,8 +1101,16 @@ function proc_run($cmd) {
                return;
        }
 
+       // If there is a lock then we don't have to check for too much worker
+       if (!Lock::set('poller_worker', 0)) {
+               return;
+       }
+
        // If there are already enough workers running, don't fork another one
-       if (poller_too_much_workers()) {
+       $quit = poller_too_much_workers();
+       Lock::remove('poller_worker');
+
+       if ($quit) {
                return;
        }
 
@@ -1379,6 +1392,46 @@ function get_server() {
        return($server);
 }
 
+function get_temppath() {
+       $a = get_app();
+
+       $temppath = get_config("system", "temppath");
+
+       if (($temppath != "") && App::directory_usable($temppath)) {
+               // We have a temp path and it is usable
+               return App::realpath($temppath);
+       }
+
+       // We don't have a working preconfigured temp path, so we take the system path.
+       $temppath = sys_get_temp_dir();
+
+       // Check if it is usable
+       if (($temppath != "") && App::directory_usable($temppath)) {
+               // Always store the real path, not the path through symlinks
+               $temppath = App::realpath($temppath);
+
+               // To avoid any interferences with other systems we create our own directory
+               $new_temppath = $temppath . "/" . $a->get_hostname();
+               if (!is_dir($new_temppath)) {
+                       /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
+                       mkdir($new_temppath);
+               }
+
+               if (App::directory_usable($new_temppath)) {
+                       // The new path is usable, we are happy
+                       set_config("system", "temppath", $new_temppath);
+                       return $new_temppath;
+               } 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 '';
+}
+
 function get_cachefile($file, $writemode = true) {
        $cache = get_itemcachepath();
 
@@ -1445,7 +1498,7 @@ function get_itemcachepath() {
 
        $itemcache = get_config('system', 'itemcache');
        if (($itemcache != "") && App::directory_usable($itemcache)) {
-               return $itemcache;
+               return App::realpath($itemcache);
        }
 
        $temppath = get_temppath();
@@ -1501,43 +1554,6 @@ function get_spoolpath() {
        return "";
 }
 
-function get_temppath() {
-       $a = get_app();
-
-       $temppath = get_config("system", "temppath");
-
-       if (($temppath != "") && App::directory_usable($temppath)) {
-               // We have a temp path and it is usable
-               return $temppath;
-       }
-
-       // We don't have a working preconfigured temp path, so we take the system path.
-       $temppath = sys_get_temp_dir();
-
-       // Check if it is usable
-       if (($temppath != "") && App::directory_usable($temppath)) {
-               // To avoid any interferences with other systems we create our own directory
-               $new_temppath = $temppath . "/" . $a->get_hostname();
-               if (!is_dir($new_temppath)) {
-                       /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
-                       mkdir($new_temppath);
-               }
-
-               if (App::directory_usable($new_temppath)) {
-                       // The new path is usable, we are happy
-                       set_config("system", "temppath", $new_temppath);
-                       return $new_temppath;
-               } 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 '';
-}
-
 /// @deprecated
 function set_template_engine(App $a, $engine = 'internal') {
 /// @note This function is no longer necessary, but keep it as a wrapper to the class method