Skip to content

Instantly share code, notes, and snippets.

@hex128
Last active July 30, 2016 17:26
Show Gist options
  • Save hex128/e2bfc60c6a62e4b67014 to your computer and use it in GitHub Desktop.
Save hex128/e2bfc60c6a62e4b67014 to your computer and use it in GitHub Desktop.
Remote Control
<?php
$APC_KEY = "remote_command";
$now = time();
$msec = 0;
$success = false;
while (!$success && $msec < 20000) {
$command = apc_fetch($APC_KEY, $success);
usleep(1000);
$msec ++;
}
apc_delete($APC_KEY);
header("Content-type: application/json");
echo json_encode([
"command" => $command,
"status" => http_response_code()
]);
<?php
$APC_KEY = "remote_command";
$command = $_REQUEST['command'];
if (!$command)
http_response_code(400);
apc_delete($APC_KEY);
if (!apc_add($APC_KEY, $command, 1))
http_response_code(500);
header("Content-type: application/json");
echo json_encode([
"command" => $command,
"status" => http_response_code()
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment