]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3920 from annando/scripts
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 19 Nov 2017 22:25:14 +0000 (17:25 -0500)
committerGitHub <noreply@github.com>
Sun, 19 Nov 2017 22:25:14 +0000 (17:25 -0500)
The poller is now the worker and we have a "scripts" folder

20 files changed:
INSTALL.txt
boot.php
doc/Install.md
doc/Message-Flow.md
doc/de/Install.md
doc/de/Message-Flow.md
doc/htconfig.md
include/dbstructure.php
include/poller.php [deleted file]
include/uimport.php
mod/admin.php
mod/install.php
mod/worker.php
scripts/daemon.php [new file with mode: 0644]
scripts/dbstructure.php [new file with mode: 0644]
scripts/worker.php [new file with mode: 0644]
src/Core/Worker.php
src/Worker/OnePoll.php
util/daemon.php [deleted file]
util/vagrant_provision.sh

index 4a88ac841748f75b180ea19831b2062b0c5b3184..bc0f4824a7c29ad53249f0bddf97c759b42c0cb3 100644 (file)
@@ -102,17 +102,17 @@ tables, so that you can start fresh.
 ****************************************************************************
 ****************************************************************************
 
-8. Set up a cron job or scheduled task to run the poller once every 5-10 
+8. Set up a cron job or scheduled task to run the worker once every 5-10 
 minutes to pick up the recent "public" postings of your friends. Example:
 
-       cd /base/directory; /path/to/php include/poller.php
+       cd /base/directory; /path/to/php scripts/worker.php
 
 Change "/base/directory", and "/path/to/php" as appropriate for your situation.
 
 If you are using a Linux server, run "crontab -e" and add a line like the 
 one shown, substituting for your unique paths and settings:
 
-*/10 * * * *   cd /home/myname/mywebsite; /usr/bin/php include/poller.php
+*/10 * * * *   cd /home/myname/mywebsite; /usr/bin/php scripts/worker.php
 
 You can generally find the location of PHP by executing "which php". If you 
 have troubles with this section please contact your hosting provider for 
@@ -285,14 +285,14 @@ cron by using something like
 
  */10 * * * * cd /var/www/friendica/friendica/ && sudo -u www-data /usr/bin/php
 -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none
--f include/poller.php
+-f scripts/worker.php
 
 This worked well for simple test cases, but the friendica-cron still failed with
 a fatal error:
 suhosin[22962]: ALERT - function within blacklist called: proc_open() (attacker
 'REMOTE_ADDR not set', file '/var/www/friendica/friendica/boot.php', line 1341)
 
-After a while I noticed, that include/poller.php calls further php script via
+After a while I noticed, that scripts/worker.php calls further php script via
 proc_open. These scripts themselves also use proc_open and fail, because they
 are NOT called with -d suhosin.executor.func.blacklist=none.
 
index 402273bddf761187143a3b47260a1d56c815ab22..ce96aa5ab18ae8b2d4520437df296f7d4426bcff 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -618,7 +618,7 @@ function is_ajax()
 /**
  * @brief Function to check if request was an AJAX (xmlhttprequest) request.
  *
- * @param boolean $via_worker boolean Is the check run via the poller?
+ * @param boolean $via_worker boolean Is the check run via the worker?
  */
 function check_db($via_worker)
 {
@@ -1064,18 +1064,6 @@ function get_max_import_size()
        return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 );
 }
 
-/**
- * @brief compatibilty wrapper for Worker::add function
- *
- * @param (integer|array) priority or parameter array, strings are deprecated and are ignored
- *
- * @return boolean "false" if proc_run couldn't be executed
- */
-function proc_run()
-{
-       $proc_args = func_get_args();
-       call_user_func_array('Friendica\Core\Worker::add', $proc_args);
-}
 
 function current_theme()
 {
index 9b7b5a94726fc4be9b17ee4afb05a540859eeb12..8f6067a875272064cf6e0bc4f23d448d50d1a6a6 100644 (file)
@@ -94,19 +94,19 @@ Registration errors should all be recoverable automatically.
 If you get any *critical* failure at this point, it generally indicates the database was not installed correctly.
 You might wish to move/rename .htconfig.php to another name and empty (called 'dropping') the database tables, so that you can start fresh.
 
-###Set up the poller
+###Set up the worker
 
-Set up a cron job or scheduled task to run the poller once every 5-10 minutes in order to perform background processing.
+Set up a cron job or scheduled task to run the worker once every 5-10 minutes in order to perform background processing.
 Example:
 
-    cd /base/directory; /path/to/php include/poller.php
+    cd /base/directory; /path/to/php scripts/worker.php
 
 Change "/base/directory", and "/path/to/php" as appropriate for your situation.
 
 If you are using a Linux server, run "crontab -e" and add a line like the
 one shown, substituting for your unique paths and settings:
 
-    */10 * * * * cd /home/myname/mywebsite; /usr/bin/php include/poller.php
+    */10 * * * * cd /home/myname/mywebsite; /usr/bin/php scripts/worker.php
 
 You can generally find the location of PHP by executing "which php".
 If you run into trouble with this section please contact your hosting provider for assistance.
index 9a6785d5992f1eea85023d0fce62011b309055e9..9692ae88cb1049b8c164e57d1e579f5ef6761242 100644 (file)
@@ -19,7 +19,7 @@ Salmon notifications arrive via mod/salmon.php.
 
 Push (pubsubhubbub) feeds arrive via mod/pubsub.php
 
-DFRN-poll feed imports arrive via include/poller.php as a scheduled task, this implements the local side of the DFRN-poll protocol.  
+DFRN-poll feed imports arrive via src/Worker/OnePoll.php as a scheduled task, this implements the local side of the DFRN-poll protocol.
 
 ### Scenario #1. Bob posts a public status message
 
@@ -28,7 +28,7 @@ There are two paths it can take - as a bbcode path to DFRN clients, and converte
 When a PuSH hub is operational, dfrn-poll clients prefer to receive their information through the PuSH channel.
 They will fall back on a daily poll in case the hub has delivery issues (this is quite common when using the default Google reference hub).
 If there is no specified hub or hubs, DFRN clients will poll at a configurable (per-contact) rate at up to 5-minute intervals.
-Feeds retrieved via dfrn-poll are bbcode and may also contain private conversations which the poller has permissions to see. 
+Feeds retrieved via dfrn-poll are bbcode and may also contain private conversations which the worker has permissions to see.
 
 ### Scenario #2. Jack replies to Bob's public message. Jack is on the Friendica/DFRN network.
 
index 2c06d797cff29dff77b80a480604505aafa19b11..20c479e1cfba73d05a96df5ab671df33ef74f92e 100644 (file)
@@ -84,13 +84,13 @@ Wenn du irgendwelche **kritischen** Fehler zu diesen Zeitpunkt erhalten solltest
 
 7. Erstelle einen Cron job oder einen regelmäßigen Task, um den Poller alle 5-10 Minuten im Hintergrund ablaufen zu lassen. Beispiel:
 
-    `cd /base/directory; /path/to/php include/poller.php`
+    `cd /base/directory; /path/to/php scripts/worker.php`
 
 Ändere "/base/directory" und "/path/to/php" auf deine Systemvorgaben.
 
 Wenn du einen Linux-Server nutzt, benutze den Befehl "crontab -e" und ergänze eine Zeile wie die Folgende; angepasst an dein System
 
-`*/10 * * * * cd /home/myname/mywebsite; /usr/bin/php include/poller.php`
+`*/10 * * * * cd /home/myname/mywebsite; /usr/bin/php scripts/worker.php`
 
 Du kannst den PHP-Pfad finden, indem du den Befehl „which php“ ausführst. 
 Wenn du Schwierigkeiten mit diesem Schritt hast, kannst du deinen Hosting-Anbieter kontaktieren. 
index 3d4c912ccfd8a4847449c6b84a2082cfe7f2e21a..8ef8704d13b6573fecb26d31efeb428eebbcb54a 100644 (file)
@@ -21,7 +21,7 @@ Salmon-Benachrichtigungen kommen via mod/salmon.php an.
 
 PuSh-Feeds (pubsubhubbub) kommen via mod/pubsub.php an.
 
-DFRN-poll Feed-Imports kommen via include/poller.php als geplanter Task an, das implementiert die lokale Bearbeitung (local side) des DFRN-Protokolls. 
+DFRN-poll Feed-Imports kommen via src/Worker/OnePoll.php als geplanter Task an, das implementiert die lokale Bearbeitung (local side) des DFRN-Protokolls.
 
 
 ### Szenario #1. Bob schreibt eine öffentliche Statusnachricht
index 684be22fbcd707ab6cf1ea4af36f3f1095e16b4b..9e0a2184dfa431e716b3893de5be8994ffceec31 100644 (file)
@@ -50,8 +50,8 @@ Example: To set the directory value please add this line to your .htconfig.php:
 * **local_block** (Boolean) - Used in conjunction with "block_public".
 * **local_search** (Boolean) - Blocks search for users who are not logged in to prevent crawlers from blocking your system.
 * **local_tags** (Boolean) - If activated, all hashtags will point to the local server.
-* **max_connections** - The maximum number of database connections which can be in use before the poller process is deferred to it's next interval.  When the system can't detect the maximum numbers of connection then this value can be used.
-* **max_connections_level** - The maximum level of connections that are allowed to let the poller start. It is a percentage value. Default value is 75.
+* **max_connections** - The maximum number of database connections which can be in use before the worker process is deferred to it's next interval.  When the system can't detect the maximum numbers of connection then this value can be used.
+* **max_connections_level** - The maximum level of connections that are allowed to let the worker start. It is a percentage value. Default value is 75.
 * **max_contact_queue** - Default value is 500.
 * **max_batch_queue** - Default value is 1000.
 * **max_processes_backend** - Maximum number of concurrent database processes for background tasks. Default value is 5.
index 1df82b1beda5b5e50e3648c77d1572187dc10f37..dde3dc6f18be5c66fa15efc1546c22794fb7dd35 100644 (file)
@@ -1757,73 +1757,3 @@ function db_definition() {
 
        return($database);
 }
-
-
-/*
- * run from command line
- */
-function dbstructure_run(&$argv, &$argc) {
-       global $a;
-
-       if (empty($a)) {
-               $a = new App(dirname(__DIR__));
-       }
-
-       @include ".htconfig.php";
-       require_once "include/dba.php";
-       dba::connect($db_host, $db_user, $db_pass, $db_data);
-       unset($db_host, $db_user, $db_pass, $db_data);
-
-       if ($argc == 2) {
-               switch ($argv[1]) {
-                       case "dryrun":
-                               update_structure(true, false);
-                               return;
-                       case "update":
-                               update_structure(true, true);
-
-                               $build = Config::get('system','build');
-                               if (!x($build)) {
-                                       Config::set('system', 'build', DB_UPDATE_VERSION);
-                                       $build = DB_UPDATE_VERSION;
-                               }
-
-                               $stored = intval($build);
-                               $current = intval(DB_UPDATE_VERSION);
-
-                               // run any left update_nnnn functions in update.php
-                               for ($x = $stored; $x < $current; $x ++) {
-                                       $r = run_update_function($x);
-                                       if (!$r) {
-                                               break;
-                                       }
-                               }
-
-                               Config::set('system','build',DB_UPDATE_VERSION);
-                               return;
-                       case "dumpsql":
-                               print_structure(db_definition());
-                               return;
-                       case "toinnodb":
-                               convert_to_innodb();
-                               return;
-               }
-       }
-
-
-       // print help
-       echo $argv[0]." <command>\n";
-       echo "\n";
-       echo "Commands:\n";
-       echo "dryrun            show database update schema queries without running them\n";
-       echo "update            update database schema\n";
-       echo "dumpsql           dump database schema\n";
-       echo "toinnodb  convert all tables from MyISAM to InnoDB\n";
-       return;
-
-}
-
-if (array_search(__FILE__,get_included_files())===0) {
-       dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
-       killme();
-}
diff --git a/include/poller.php b/include/poller.php
deleted file mode 100644 (file)
index 6fcf4c7..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-use Friendica\App;
-use Friendica\Core\Worker;
-use Friendica\Core\Config;
-
-// Ensure that poller.php is executed from the base path of the installation
-if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
-       $directory = dirname($_SERVER["argv"][0]);
-
-       if (substr($directory, 0, 1) != "/") {
-               $directory = $_SERVER["PWD"]."/".$directory;
-       }
-       $directory = realpath($directory."/..");
-
-       chdir($directory);
-}
-
-require_once "boot.php";
-require_once "include/dba.php";
-
-$a = new App(dirname(__DIR__));
-
-require_once ".htconfig.php";
-dba::connect($db_host, $db_user, $db_pass, $db_data);
-unset($db_host, $db_user, $db_pass, $db_data);
-
-Config::load();
-
-// Check the database structure and possibly fixes it
-check_db(true);
-
-// Quit when in maintenance
-if (Config::get('system', 'maintenance', true)) {
-       return;
-}
-
-$a->set_baseurl(Config::get('system', 'url'));
-
-load_hooks();
-
-$run_cron = (($_SERVER["argc"] <= 1) || ($_SERVER["argv"][1] != "no_cron"));
-Worker::processQueue($run_cron);
-
-Worker::unclaimProcess();
-
-$a->end_process();
-
-killme();
-
index e0edb7091d773f61cd149388c2118633293dcea9..93f978c0778a31c0bba201e93f179a6a303d22f0 100644 (file)
@@ -189,7 +189,7 @@ function import_account(App $a, $file) {
                        }
                }
                if ($contact['uid'] == $olduid && $contact['self'] == '0') {
-                       // set contacts 'avatar-date' to NULL_DATE to let poller to update urls
+                       // set contacts 'avatar-date' to NULL_DATE to let worker to update urls
                        $contact["avatar-date"] = NULL_DATE;
 
                        switch ($contact['network']) {
index ee456a23f0ea01eba03d60a9ac6f131ad297df8e..7bb683fe8dde68f7c0da6fc8a4ac60a94e1f5c3b 100644 (file)
@@ -1237,7 +1237,7 @@ function admin_page_site(App $a) {
                '$timeout'              => array('timeout', t("Network timeout"), (x(Config::get('system','curl_timeout'))?Config::get('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
                '$maxloadavg'           => array('maxloadavg', t("Maximum Load Average"), ((intval(Config::get('system','maxloadavg')) > 0)?Config::get('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
                '$maxloadavg_frontend'  => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(Config::get('system','maxloadavg_frontend')) > 0)?Config::get('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
-               '$min_memory'           => array('min_memory', t("Minimal Memory"), ((intval(Config::get('system','min_memory')) > 0)?Config::get('system','min_memory'):0), t("Minimal free memory in MB for the poller. Needs access to /proc/meminfo - default 0 (deactivated).")),
+               '$min_memory'           => array('min_memory', t("Minimal Memory"), ((intval(Config::get('system','min_memory')) > 0)?Config::get('system','min_memory'):0), t("Minimal free memory in MB for the worker. Needs access to /proc/meminfo - default 0 (deactivated).")),
                '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
                '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(Config::get('system','optimize_fragmentation')) > 0)?Config::get('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
 
@@ -1264,7 +1264,7 @@ function admin_page_site(App $a) {
                '$rino'                 => array('rino', t("RINO Encryption"), intval(Config::get('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")),
 
                '$worker_queues'        => array('worker_queues', t("Maximum number of parallel workers"), Config::get('system','worker_queues'), t("On shared hosters set this to 2. On larger systems, values of 10 are great. Default value is 4.")),
-               '$worker_dont_fork'     => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), Config::get('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of poller calls in your crontab.")),
+               '$worker_dont_fork'     => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), Config::get('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of worker calls in your crontab.")),
                '$worker_fastlane'      => array('worker_fastlane', t("Enable fastlane"), Config::get('system','worker_fastlane'), t("When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.")),
                '$worker_frontend'      => array('worker_frontend', t('Enable frontend worker'), Config::get('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())),
 
index 2d0362c9526b11a53b5eb65f1aebcc5dccf8f60d..9c9d60eeffbe535c342117773318c347a5c1b208 100755 (executable)
@@ -317,7 +317,7 @@ function check_php(&$phpath, &$checks) {
        $help = "";
        if (!$passed) {
                $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
-               $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-poller'>'Setup the poller'</a>") . EOL;
+               $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-worker'>'Setup the worker'</a>") . EOL;
                $help .= EOL . EOL;
                $tpl = get_markup_template('field_input.tpl');
                $help .= replace_macros($tpl, array(
@@ -545,7 +545,7 @@ function what_next() {
        $baseurl = System::baseUrl();
        return
                t('<h1>What next</h1>')
-               ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
+               ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
                .t('Please see the file "INSTALL.txt".')
                ."</p><p>"
                .t("Go to your new Friendica node <a href='$baseurl/register'>registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.")
index f540010bd64102b0e2f21f1517bd6a6851f530b9..d6ecbecc264935036eb1427e72f65f9c4da3ad62 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * @file mod/worker.php
- * @brief Module for running the poller as frontend process
+ * @brief Module for running the worker as frontend process
  */
 
 use Friendica\Core\Worker;
diff --git a/scripts/daemon.php b/scripts/daemon.php
new file mode 100644 (file)
index 0000000..76668ad
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @file util/daemon.php
+ * @brief Run the worker from a daemon.
+ *
+ * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
+ */
+function shutdown() {
+       posix_kill(posix_getpid(), SIGHUP);
+}
+
+if (in_array("start", $_SERVER["argv"])) {
+       $mode = "start";
+}
+
+if (in_array("stop", $_SERVER["argv"])) {
+       $mode = "stop";
+}
+
+if (in_array("status", $_SERVER["argv"])) {
+       $mode = "status";
+}
+
+if (!isset($mode)) {
+       die("Please use either 'start', 'stop' or 'status'.\n");
+}
+
+@include(".htconfig.php");
+
+if (!isset($pidfile)) {
+       die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n".
+               '$pidfile = "/path/to/daemon.pid";'."\n");
+}
+
+if (in_array($mode, array("stop", "status"))) {
+       $pid = @file_get_contents($pidfile);
+
+       if (!$pid) {
+               die("Pidfile wasn't found. Is the daemon running?\n");
+       }
+}
+
+if ($mode == "status") {
+       if (posix_kill($pid, 0)) {
+               die("Daemon process $pid is running.\n");
+       }
+
+       unlink($pidfile);
+
+       die("Daemon process $pid isn't running.\n");
+}
+
+if ($mode == "stop") {
+       posix_kill($pid, SIGTERM);
+
+       unlink($pidfile);
+
+       die("Worker daemon process $pid was killed.\n");
+}
+
+echo "Starting worker daemon.\n";
+
+if (isset($a->config['php_path'])) {
+       $php = $a->config['php_path'];
+} else {
+       $php = "php";
+}
+
+// Switch over to daemon mode.
+if ($pid = pcntl_fork())
+       return;     // Parent
+
+fclose(STDIN);  // Close all of the standard
+fclose(STDOUT); // file descriptors as we
+fclose(STDERR); // are running as a daemon.
+
+register_shutdown_function('shutdown');
+
+if (posix_setsid() < 0)
+       return;
+
+if ($pid = pcntl_fork())
+       return;     // Parent
+
+$pid = getmypid();
+file_put_contents($pidfile, $pid);
+
+// Now running as a daemon.
+while (true) {
+       // Just to be sure that this script really runs endlessly
+       set_time_limit(0);
+
+       // Call the worker
+       $cmdline = $php.' scripts/worker.php';
+
+       exec($cmdline);
+
+       // Now sleep for 5 minutes
+       sleep(300);
+}
diff --git a/scripts/dbstructure.php b/scripts/dbstructure.php
new file mode 100644 (file)
index 0000000..cf14c92
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @file scripts/dbstructure.php
+ * @brief Does database updates from the command line
+ */
+
+require_once 'include/dbstructure.php';
+
+use Friendica\App;
+
+$a = new App(dirname(__DIR__));
+
+@include ".htconfig.php";
+require_once "include/dba.php";
+dba::connect($db_host, $db_user, $db_pass, $db_data);
+unset($db_host, $db_user, $db_pass, $db_data);
+
+if ($_SERVER["argc"] == 2) {
+       switch ($_SERVER["argv"][1]) {
+               case "dryrun":
+                       update_structure(true, false);
+                       return;
+               case "update":
+                       update_structure(true, true);
+
+                       $build = Config::get('system','build');
+                       if (!x($build)) {
+                               Config::set('system', 'build', DB_UPDATE_VERSION);
+                               $build = DB_UPDATE_VERSION;
+                       }
+
+                       $stored = intval($build);
+                       $current = intval(DB_UPDATE_VERSION);
+
+                       // run any left update_nnnn functions in update.php
+                       for ($x = $stored; $x < $current; $x ++) {
+                               $r = run_update_function($x);
+                               if (!$r) {
+                                       break;
+                               }
+                       }
+
+                       Config::set('system','build',DB_UPDATE_VERSION);
+                       return;
+               case "dumpsql":
+                       print_structure(db_definition());
+                       return;
+               case "toinnodb":
+                       convert_to_innodb();
+                       return;
+       }
+}
+
+// print help
+echo $_SERVER["argv"][0]." <command>\n";
+echo "\n";
+echo "Commands:\n";
+echo "dryrun           show database update schema queries without running them\n";
+echo "update           update database schema\n";
+echo "dumpsql          dump database schema\n";
+echo "toinnodb convert all tables from MyISAM to InnoDB\n";
+killme();
+
diff --git a/scripts/worker.php b/scripts/worker.php
new file mode 100644 (file)
index 0000000..6182895
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+use Friendica\App;
+use Friendica\Core\Worker;
+use Friendica\Core\Config;
+
+// Ensure that worker.php is executed from the base path of the installation
+if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
+       $directory = dirname($_SERVER["argv"][0]);
+
+       if (substr($directory, 0, 1) != "/") {
+               $directory = $_SERVER["PWD"]."/".$directory;
+       }
+       $directory = realpath($directory."/..");
+
+       chdir($directory);
+}
+
+require_once "boot.php";
+require_once "include/dba.php";
+
+$a = new App(dirname(__DIR__));
+
+require_once ".htconfig.php";
+dba::connect($db_host, $db_user, $db_pass, $db_data);
+unset($db_host, $db_user, $db_pass, $db_data);
+
+Config::load();
+
+// Check the database structure and possibly fixes it
+check_db(true);
+
+// Quit when in maintenance
+if (Config::get('system', 'maintenance', true)) {
+       return;
+}
+
+$a->set_baseurl(Config::get('system', 'url'));
+
+load_hooks();
+
+$run_cron = (($_SERVER["argc"] <= 1) || ($_SERVER["argv"][1] != "no_cron"));
+Worker::processQueue($run_cron);
+
+Worker::unclaimProcess();
+
+$a->end_process();
+
+killme();
+
index 9e69d4173a807db96131eebe276465b5a9961ddd..2cfb4de742be6c3a715393bd0f268b6c97e6c868 100644 (file)
@@ -108,7 +108,7 @@ class Worker {
                                }
                        }
 
-                       // To avoid the quitting of multiple pollers only one poller at a time will execute the check
+                       // To avoid the quitting of multiple workers only one worker at a time will execute the check
                        if (Lock::set('poller_worker', 0)) {
                                $stamp = (float)microtime(true);
                                // Count active workers and compare them with a maximum value that depends on the load
@@ -126,7 +126,7 @@ class Worker {
                                self::$db_duration += (microtime(true) - $stamp);
                        }
 
-                       // Quit the poller once every 5 minutes
+                       // Quit the worker once every 5 minutes
                        if (time() > ($starttime + 300)) {
                                logger('Process lifetime reached, quitting.', LOGGER_DEBUG);
                                return;
@@ -152,7 +152,7 @@ class Worker {
        /**
         * @brief Returns the highest priority in the worker queue that isn't executed
         *
-        * @return integer Number of active poller processes
+        * @return integer Number of active worker processes
         */
        private static function highestPriority() {
                $condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
@@ -431,7 +431,7 @@ class Worker {
                // Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
                $max = Config::get("system", "max_connections");
 
-               // Fetch the percentage level where the poller will get active
+               // Fetch the percentage level where the worker will get active
                $maxlevel = Config::get("system", "max_connections_level", 75);
 
                if ($max == 0) {
@@ -636,9 +636,9 @@ class Worker {
        }
 
        /**
-        * @brief Returns the number of active poller processes
+        * @brief Returns the number of active worker processes
         *
-        * @return integer Number of active poller processes
+        * @return integer Number of active worker processes
         */
        private static function activeWorkers() {
                $workers = dba::fetch_first("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'Worker.php'");
@@ -840,7 +840,7 @@ class Worker {
                        return;
                }
 
-               // Do we have "proc_open"? Then we can fork the poller
+               // Do we have "proc_open"? Then we can fork the worker
                if (function_exists("proc_open")) {
                        // When was the last time that we called the worker?
                        // Less than one minute? Then we quit
@@ -861,7 +861,7 @@ class Worker {
 
                        self::runCron();
 
-                       logger('Call poller', LOGGER_DEBUG);
+                       logger('Call worker', LOGGER_DEBUG);
                        self::spawnWorker();
                        return;
                }
@@ -912,7 +912,7 @@ class Worker {
        }
 
        public static function spawnWorker() {
-               $args = array("include/poller.php", "no_cron");
+               $args = array("scripts/worker.php", "no_cron");
                get_app()->proc_run($args);
        }
 
@@ -999,7 +999,7 @@ class Worker {
                        dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
                }
 
-               // Should we quit and wait for the poller to be called as a cronjob?
+               // Should we quit and wait for the worker to be called as a cronjob?
                if ($dont_fork) {
                        return true;
                }
@@ -1017,7 +1017,7 @@ class Worker {
                        return true;
                }
 
-               // Now call the poller to execute the jobs that we just added to the queue
+               // Now call the worker to execute the jobs that we just added to the queue
                self::spawnWorker();
 
                return true;
index 11e7d30c3f9dbe608c377f1a688e308fe144ae95..374c69f13f1cd519194b2981b6440afe1a3a004f 100644 (file)
@@ -190,7 +190,7 @@ Class OnePoll
 
 
                        if (!strlen($handshake_xml) || ($html_code >= 400) || !$html_code) {
-                               logger("poller: $url appears to be dead - marking for death ");
+                               logger("$url appears to be dead - marking for death ");
 
                                // dead connection - might be a transient event, or this might
                                // mean the software was uninstalled or the domain expired.
@@ -206,7 +206,7 @@ Class OnePoll
                        }
 
                        if (!strstr($handshake_xml, '<')) {
-                               logger('poller: response from ' . $url . ' did not contain XML.');
+                               logger('response from ' . $url . ' did not contain XML.');
 
                                mark_for_death($contact);
 
@@ -220,7 +220,7 @@ Class OnePoll
                        $res = parse_xml_string($handshake_xml);
 
                        if (intval($res->status) == 1) {
-                               logger("poller: $url replied status 1 - marking for death ");
+                               logger("$url replied status 1 - marking for death ");
 
                                // we may not be friends anymore. Will keep trying for one month.
                                // set the last-update so we don't keep polling
@@ -229,7 +229,7 @@ Class OnePoll
 
                                mark_for_death($contact);
                        } elseif ($contact['term-date'] > NULL_DATE) {
-                               logger("poller: $url back from the dead - removing mark for death");
+                               logger("$url back from the dead - removing mark for death");
                                unmark_for_death($contact);
                        }
 
@@ -264,7 +264,7 @@ Class OnePoll
                        }
 
                        if ($final_dfrn_id != $orig_id) {
-                               logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
+                               logger('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
                                // did not decode properly - cannot trust this site
                                return;
                        }
@@ -555,9 +555,9 @@ Class OnePoll
                }
 
                if ($xml) {
-                       logger('poller: received xml : ' . $xml, LOGGER_DATA);
+                       logger('received xml : ' . $xml, LOGGER_DATA);
                        if (!strstr($xml, '<')) {
-                               logger('poller: post_handshake: response from ' . $url . ' did not contain XML.');
+                               logger('post_handshake: response from ' . $url . ' did not contain XML.');
 
                                $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
                                dba::update('contact', $fields, array('id' => $contact['id']));
@@ -590,7 +590,7 @@ Class OnePoll
                        logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update);
 
                        if (strlen($hub) && $hub_update && (($contact['rel'] != CONTACT_IS_FOLLOWER) || $contact['network'] == NETWORK_FEED)) {
-                               logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
+                               logger('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
                                $hubs = explode(',', $hub);
                                if (count($hubs)) {
                                        foreach ($hubs as $h) {
diff --git a/util/daemon.php b/util/daemon.php
deleted file mode 100644 (file)
index 4accef3..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * @file util/daemon.php
- * @brief Run the poller from a daemon.
- *
- * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
- */
-function shutdown() {
-       posix_kill(posix_getpid(), SIGHUP);
-}
-
-if (in_array("start", $_SERVER["argv"])) {
-       $mode = "start";
-}
-
-if (in_array("stop", $_SERVER["argv"])) {
-       $mode = "stop";
-}
-
-if (in_array("status", $_SERVER["argv"])) {
-       $mode = "status";
-}
-
-if (!isset($mode)) {
-       die("Please use either 'start', 'stop' or 'status'.\n");
-}
-
-@include(".htconfig.php");
-
-if (!isset($pidfile)) {
-       die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n".
-               '$pidfile = "/path/to/daemon.pid";'."\n");
-}
-
-if (in_array($mode, array("stop", "status"))) {
-       $pid = @file_get_contents($pidfile);
-
-       if (!$pid) {
-               die("Pidfile wasn't found. Is the daemon running?\n");
-       }
-}
-
-if ($mode == "status") {
-       if (posix_kill($pid, 0)) {
-               die("Daemon process $pid is running.\n");
-       }
-
-       unlink($pidfile);
-
-       die("Daemon process $pid isn't running.\n");
-}
-
-if ($mode == "stop") {
-       posix_kill($pid, SIGTERM);
-
-       unlink($pidfile);
-
-       die("Worker daemon process $pid was killed.\n");
-}
-
-echo "Starting worker daemon.\n";
-
-if (isset($a->config['php_path'])) {
-       $php = $a->config['php_path'];
-} else {
-       $php = "php";
-}
-
-// Switch over to daemon mode.
-if ($pid = pcntl_fork())
-       return;     // Parent
-
-fclose(STDIN);  // Close all of the standard
-fclose(STDOUT); // file descriptors as we
-fclose(STDERR); // are running as a daemon.
-
-register_shutdown_function('shutdown');
-
-if (posix_setsid() < 0)
-       return;
-
-if ($pid = pcntl_fork())
-       return;     // Parent
-
-$pid = getmypid();
-file_put_contents($pidfile, $pid);
-
-// Now running as a daemon.
-while (true) {
-       // Just to be sure that this script really runs endlessly
-       set_time_limit(0);
-
-       // Call the poller
-       $cmdline = $php.' include/poller.php';
-
-       exec($cmdline);
-
-       // Now sleep for 5 minutes
-       sleep(300);
-}
index bf2599445e715b47dfd729f9d88871255408c77f..2029d97d58807cbfede8e29fb071cc11cff3569b 100644 (file)
@@ -88,7 +88,7 @@ echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_ge
 $MYSQL -uroot -proot friendica < /vagrant/friendica_test_data.sql
 
 # create cronjob - activate if you have enough memory in you dev VM
-echo "*/10 * * * * cd /vagrant; /usr/bin/php include/poller.php" >> friendicacron
+echo "*/10 * * * * cd /vagrant; /usr/bin/php scripts/worker.php" >> friendicacron
 sudo crontab friendicacron
 sudo rm friendicacron