-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast.php
43 lines (36 loc) · 1.22 KB
/
fast.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
<?php
use Invoke\Container;
use Invoke\Invoke;
use Workerman\Connection\ConnectionInterface;
use Workerman\Protocols\Http\Request;
use Workerman\Worker;
require_once __DIR__ . "/vendor/autoload.php";
require_once __DIR__ . "/bootstrap/init.php";
startTasks();
$httpWorker = new Worker("http://0.0.0.0:8080");
$httpWorker->name = 'fast';
$httpWorker->count = (int)shell_exec("nproc") * 4;
$httpWorker->onMessage = function (ConnectionInterface $connection, Request $request) {
$methodName = trim(trim($request->path()), "/");
$params = json_decode($request->rawBody(), true);
if (empty($methodName)) {
$connection->send("Powered by Fast&Invoke");
} else {
try {
$result = Container::get(Invoke::class)
->serve(Container::get(Invoke::class), [
"name" => "$methodName",
"params" => $params,
]);
$connection->send(json_encode([
"result" => $result,
]));
} catch (Throwable $exception) {
$connection->send(json_encode([
"error" => $exception::class,
"message" => $exception->getMessage(),
]));
}
}
};
Worker::runAll();