Skip to content

Instantly share code, notes, and snippets.

@lornajane
Created June 7, 2017 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lornajane/513d1007d1f587f6fe6fb3cd08d7dc30 to your computer and use it in GitHub Desktop.
Save lornajane/513d1007d1f587f6fe6fb3cd08d7dc30 to your computer and use it in GitHub Desktop.
<?php
$action_filename = "action.php";
ob_start();
if($_POST){
switch($_SERVER['SCRIPT_NAME']) {
case "/init":
echo "OK\n";
break;
case "/run":
// load the code, assume function "main"
require($action_filename);
// parse incoming data, JSON format, field "value"
$data = json_decode(file_get_contents("php://input"), true);
// pass args to function
$output = main($data['value']);
// return result
header("Content-Type: application/json");
echo json_encode($output);
break;
default:
// do nothing
}
$output_buffer = ob_get_contents();
header("Content-Length: " . mb_strlen($output_buffer));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment