Created
June 7, 2017 07:18
-
-
Save lornajane/513d1007d1f587f6fe6fb3cd08d7dc30 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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