Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2015 06:27
Show Gist options
  • Save anonymous/b1afdd24b154730d07d7 to your computer and use it in GitHub Desktop.
Save anonymous/b1afdd24b154730d07d7 to your computer and use it in GitHub Desktop.
<?php
$collector->addRoute("GET", "/change/{id:[0-9]+}", function (RequestInterface $request, SocketInterface $socket, array $parameters) use ($database) {
if (!isset($parameters["id"])) {
return;
}
$module = (
yield $database
->table("module")
->select()
->where("id = ?", $parameters["id"])
->first()
);
if (!$module) {
return;
}
$name = $module["name"];
$context = Fork::spawn(function () use ($name) {
$lock = getenv("HR_BASE") . "/lock";
while (file_exists($lock)) {
usleep(250);
}
touch($lock);
exec(getenv("HR_BASE") . "/bin/beep boop:change --only={$name}");
unlink($lock);
yield;
});
yield $context->join();
$back = "/changes";
if ($alternative = $request->getUri()->getQueryValue("back")) {
$back = urldecode($alternative);
}
yield new Response(302, ["Location" => $back]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment