raducostea's avatar

Lumen slow response

Looks like i am getting a big difference on the following test

$app->get('/', function () {
    return ['test' => 1];
});

This takes about 450ms and returns {'test': 1}

The following

$app->get('/', function () {
    echo json_encode['test' => 1];
    exit;
});

This takes about 170ms which is a big difference especially when you have a lot of requests to your api.

So probably something heavy happens in the response factory but i could not find it nor i could find a way to overwrite it with my own method. Any ideas?

Thanks

0 likes
3 replies
raducostea's avatar

Looks like i can do something like this in a middlewere

$response = $next($request);

        header('Content-Type: application/json');
        echo $response->getContent();
        exit;

But i doesn't look very nice.

leolam2005's avatar

No, Lumen is very fast. It only takes 99ms to retrieve 18 products with eager load likes count, categories, shop, tag... etc...

@raducostea

Check your set up.

@mikerh

Reason Lumen is not fastest but very attractive is that most of my Laravel things/models/knowledge can be directly applied on Lumen. It is friendly to developer and still blazing fast.

1 like

Please or to participate in this conversation.