fenci/index.php
2020-09-30 19:56:27 +08:00

35 lines
951 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
date_default_timezone_set("PRC");
ini_set('memory_limit', '1024M');
mb_internal_encoding('UTF-8');
include 'vendor/autoload.php';
include 'routes.php';
use Workerman\Worker;
Worker::$stdoutFile = __DIR__ . '/stdout.log';
// 创建一个Worker监听2345端口使用http协议通讯
$http_worker = new Worker("http://0.0.0.0:10008");
$http_worker->name = 'Http Server Worker';
// 启动4个进程对外提供服务
$http_worker->count = 2;
// 接收到浏览器发送的数据时回复数据给浏览器
$http_worker->onMessage = function ($connection,$request) {
$t1 = microtime(true);
$response = \app\helper\Router::process($request);
$t2 = microtime(true);
$time = round($t2 - $t1, 3);
$mem = memory_get_usage() / (1.0 * 1024 * 1024);
$response->withHeaders([
'X-Time' => $time .'ms',
'X-Memory' => ceil($mem).'MB'
]);
$connection->send($response);
};
// 运行worker
Worker::runAll();