-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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 GitHub Actions / Test
|
||
// | ||
// these are the external commands we want to run, and | ||
// the directory paths to be provided as their argument | ||
|
@@ -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 | ||
// | ||
|