1
0
Fork 0

Merge pull request #3920 from annando/scripts

The poller is now the worker and we have a "scripts" folder
This commit is contained in:
Hypolite Petovan 2017-11-19 17:25:14 -05:00 committed by GitHub
commit 81647cefed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 110 additions and 129 deletions

View 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.

View file

@ -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()
{

View 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.

View 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.

View 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.

View 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

View 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.

View 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();
}

View 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']) {

View 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())),

View file

@ -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.")

View 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;

View file

@ -1,7 +1,7 @@
<?php
/**
* @file util/daemon.php
* @brief Run the poller from a daemon.
* @brief Run the worker from a daemon.
*
* This script was taken from http://php.net/manual/en/function.pcntl-fork.php
*/
@ -90,8 +90,8 @@ while (true) {
// Just to be sure that this script really runs endlessly
set_time_limit(0);
// Call the poller
$cmdline = $php.' include/poller.php';
// Call the worker
$cmdline = $php.' scripts/worker.php';
exec($cmdline);

63
scripts/dbstructure.php Normal file
View file

@ -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();

View file

@ -3,7 +3,7 @@ use Friendica\App;
use Friendica\Core\Worker;
use Friendica\Core\Config;
// Ensure that poller.php is executed from the base path of the installation
// 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]);

View 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;

View 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) {

View 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