Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gbxyz committed Jan 21, 2024
1 parent 2db5f40 commit 07e3fb1
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions RDAP/RootServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,15 @@ class RootServer extends Server {
private const ROOTDIR = '/tmp/tlds';
private const RARDIR = '/tmp/registrars';

/**
* @var resource[]
*/
private array $procs = [];

/**
* load the registry data and then start the server
*/
public function start() : bool {
fwrite($this->STDERR, "loading registry data...\n");

// tell updateData() not to schedule a cleanProcesses() call
// tell updateData() not to run the updater scripts in the background
$this->updateData(false);

// this is blocking, so we don't start the server until we're sure we can answer
while (count($this->procs) > 0) {
if (pcntl_sigtimedwait([SIGCHLD], $i, 0, 100_000)) $this->cleanProcesses(true);
}

fwrite($this->STDERR, "ready to accept requests!\n");

return \OpenSwoole\HTTP\Server::start();
Expand Down Expand Up @@ -78,9 +68,9 @@ protected function generateResponse(Request $request, Response $response) : int

/**
* update data
* @param bool $cleanup if true, a timer will be set to call cleanProcesses() after 5000ms
* @param bool $$background if true, scripts will be run in the background
*/
protected function updateData(bool $cleanup=true) : void {
protected function updateData(bool $background=true) : void {

Check failure on line 73 in RDAP/RootServer.php

View workflow job for this annotation

GitHub Actions / Test

PHPDoc tag @param has invalid value (bool $$background if true, scripts will be run in the background): Unexpected token "$$background", expected variable at offset 42
//
// these are the external commands we want to run, and
// the directory paths to be provided as their argument
Expand All @@ -90,30 +80,13 @@ protected function updateData(bool $cleanup=true) : void {
dirname(__DIR__).'/bin/registrars.pl' => self::RARDIR,
];

//
// get all the currently running commands
//
$running = [];
foreach ($this->procs as $proc) {
$s = proc_get_status($proc);
if (true === $s['running']) $running[] = $s['command'];
}

$p = [];
foreach ($cmds as $cmd => $dir) {
//
// command still running, so skip
//
if (in_array($cmd, $running)) continue;

if (!file_exists($dir)) mkdir($dir, 0755, true);
$fmt = '%s %s 1>&2';
if ($background) $fmt .= ' &';

$proc = proc_open([$cmd, $dir], [], $p);
if (false !== $proc) $this->procs[] = $proc;
shell_exec(sprintf($fmt, escapeshellcmd($cmd), escapeshellarg($dir)));
}

if ($cleanup) $this->after(5000, fn() => $this->cleanProcesses()); // @phpstan-ignore-line

//
// schedule a refresh
//
Expand Down

0 comments on commit 07e3fb1

Please sign in to comment.