forked from csev/cc4e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping.php
56 lines (43 loc) · 1.16 KB
/
ping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require_once "tsugi/config.php";
use \Tsugi\Util\U;
require_once "sandbox/sandbox.php";
require_once "play_util.php";
$PING_CACHE = 20;
$secret = U::appCacheGet("pingsecret", null);
if ( $secret === null ) {
U::appCacheSet("pingsecret", "42");
$secret = U::appCacheGet("pingsecret", null);
}
header("Content-type: application/json; charset=utf-8");
if ( $secret != '42' ) {
$retval = new \stdCLass();
$retval->pingstatus = "No APC";
echo(json_encode($retval, JSON_PRETTY_PRINT));
return;
}
$prev = U::appCacheGet("pingtime", 0);
$retval = U::appCacheGet("pingretval", null);
if ( $retval == null ) $retval = new \stdCLass();
$now = time();
$delta = $now - $prev;
$retval->pingdelta = $delta;
if ( $delta < $PING_CACHE ) {
$retval->pingstatus = "Cache";
echo(json_encode($retval, JSON_PRETTY_PRINT));
return;
}
U::appCacheSet("pingtime", $now);
$code = <<<EOF
#include <stdio.h>
main() {
printf("Hello world\\n");
}
EOF;
$input = "";
$main = null;
$retval = cc4e_compile($code, $input, $main, "ping.php");
$retval->pingdelta = $delta;
U::appCacheSet("pingretval", $retval);
$retval->pingstatus = "Compile";
echo(json_encode($retval, JSON_PRETTY_PRINT));