Symfony всегда занимает 100+ мс для обработки запросаPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Symfony всегда занимает 100+ мс для обработки запроса

Сообщение Anonymous »

Я работал над Symfony 5.4 и попытался войти в систему сроков выполнения запроса. Я сделал Eventlistner, который слушает kernelevents :: Запрос: < /p>

Код: Выделить всё

class ApiLoggerListener
{
#[AsEventListener(event: KernelEvents::REQUEST)]
public function onRequest(RequestEvent $event): void
{
$request->attributes->set('_timestamp', microtime(true));
}

#[AsEventListener(event: KernelEvents::RESPONSE)]
public function onResponse(ResponseEvent $event): void
{
$now = microtime(true);
$response = $event->getResponse();
$request = $event->getRequest();
$route = $request->attributes->get('_route');
$dt = $request->attributes->get('_timestamp');

//...

$executionStart = $request->attributes->get('start-execution', null);
$executionEnd = $request->attributes->get('end-execution', null);
if ($executionStart && $executionEnd && $dt) {
$inputTime = (int)(($executionStart - $dt) * 1000); // ms took to reach controller after onRequest()
$outputTime = (int)(($now - $executionEnd) * 1000); // ms took to reach onResponse() after controller
$executionTime = (int)(($executionEnd - $executionStart) * 1000); // ms contoller took to handle request and produce response
$timing = "input=$inputTime;ouput=$outputTime;execution=$executionTime;";
$response->headers->set('Server-Timing', $timing);
}
}
}
< /code>
и я добавил это в Controller: < /p>
    #[Route('/foo', name: 'foo', methods: [Request::METHOD_POST)]
public function myGloriousAction(
Request $request,
// ...
): ApiResponse {
$request->attributes->set('start-execution', microtime(true));
// $result = ...
$request->attributes->set('end-execution', microtime(true));
return new ApiResponse($result);
}
и то, что я вижу каждый раз: input = 100; oupul = 6; выполнение = 15; . Что потребовалось так долго, чтобы обрабатывать запрос, прежде чем он достигнет контроллера?


Подробнее здесь: https://stackoverflow.com/questions/796 ... le-request
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»