-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
38 lines (31 loc) · 987 Bytes
/
index.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
<?php
// kphp -F --composer-root=$(pwd) --composer-no-dev index.php
// ./build/server -H 8088 --use-utf8 --workers-num 5 -q &
use KLua\KLua;
use KLua\KLuaConfig;
use Revobot\Handlers\JobWorkerHandler;
use Revobot\Router;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/lang.php';
if (KPHP_COMPILER_VERSION) {
KLua::loadFFI();
}
const LUA_MAX_MEM_BYTES = 1024 * 1024;
global $NoCheck;
$NoCheck = false;
$lua_config = new KLuaConfig();
$lua_config->preload_stdlib = ['base', 'string', 'math', 'utf8'];
$lua_config->alloc_hook = function ($alloc_size) {
$stats = KLua::getStats();
$mem_free = LUA_MAX_MEM_BYTES - $stats->mem_usage;
return $mem_free >= $alloc_size;
};
KLua::init($lua_config);
if (PHP_SAPI !== 'cli' && isset($_SERVER["JOB_ID"])) {
(new JobWorkerHandler)->handle('');
} else {
$router = new Router();
$url = $_SERVER['PHP_SELF'];
$router->handleRequest((string)$url);
}