mirror of
https://github.com/friendica/friendica
synced 2025-04-27 15:10:11 +00:00
Using getopt for CLI arguments (#5446)
* Adding Argument class to Friendica * Adding Argument class to Friendica * Adding Argument class to Friendica * fixing arguments for `spawnWorker` * Adding `use Friendica\BaseObject` to `ApiTest.php` * Refactoring the argument-usages of Friendica * Refactoring the argument-usages of Friendica * removing superfluous []
This commit is contained in:
parent
ea24ac9d95
commit
cd52d0b3e9
5 changed files with 38 additions and 15 deletions
23
src/App.php
23
src/App.php
|
@ -1116,19 +1116,32 @@ class App
|
|||
return false;
|
||||
}
|
||||
|
||||
public function proc_run($args)
|
||||
/**
|
||||
* Executes a child process with 'proc_open'
|
||||
*
|
||||
* @param string $command The command to execute
|
||||
* @param array $args Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ]
|
||||
*/
|
||||
public function proc_run($command, $args)
|
||||
{
|
||||
if (!function_exists('proc_open')) {
|
||||
return;
|
||||
}
|
||||
|
||||
array_unshift($args, $this->getConfigValue('config', 'php_path', 'php'));
|
||||
$cmdline = $this->getConfigValue('config', 'php_path', 'php') . $command;
|
||||
|
||||
for ($x = 0; $x < count($args); $x ++) {
|
||||
$args[$x] = escapeshellarg($args[$x]);
|
||||
foreach ($args as $key => $value) {
|
||||
if (!is_null($value) && is_bool($value) && !$value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cmdline .= ' --' . $key;
|
||||
if (!is_null($value) && !is_bool($value)) {
|
||||
$cmdline .= ' ' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
$cmdline = implode(' ', $args);
|
||||
$cmdline = escapeshellarg($cmdline);
|
||||
|
||||
if ($this->min_memory_reached()) {
|
||||
return;
|
||||
|
|
|
@ -1010,13 +1010,11 @@ class Worker
|
|||
*/
|
||||
public static function spawnWorker($do_cron = false)
|
||||
{
|
||||
$args = ["bin/worker.php"];
|
||||
$command = 'bin/worker.php';
|
||||
|
||||
if (!$do_cron) {
|
||||
$args[] = "no_cron";
|
||||
}
|
||||
$args = [ 'cron' => $do_cron ];
|
||||
|
||||
get_app()->proc_run($args);
|
||||
get_app()->proc_run($command, $args);
|
||||
|
||||
// after spawning we have to remove the flag.
|
||||
if (Config::get('system', 'worker_daemon_mode', false)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue