Skip to content

Conversation

@Scarbous
Copy link

@Scarbous Scarbous commented Oct 22, 2025

We use tideways in our projects.
We want to use this middleware to enable the request based profiling.

https://support.tideways.com/documentation/setup/installation/frankenphp.html#code-changes-to-frankenphp_handle_request-callback

@nicolas-grekas
Copy link

FYI, in Symfony 7.4, support for FrankenPHP will work out of the box, no php-runtime package will be required.

@Scarbous
Copy link
Author

Thank you @nicolas-grekas, I will add the middleware PR also for the runtime in symfony.

@Scarbous Scarbous force-pushed the feature/add-frankenphp-symfony-middlware branch from bea4709 to 410eaa3 Compare October 22, 2025 08:20
@andrew-demb
Copy link

Is it necessary to use low-level middleware, but not to decorate Symfony's kernel instance, which would provide a generic solution?

@Scarbous
Copy link
Author

@andrew-demb I have considered using Symfony events, but I would like to be able to wrap the entire handle process.

I want to use a middleware for tideways like this:

class TidewaysMiddleware implements MiddlewareInterface
{
    public function wrap(callable $handler, array $server): void
    {
        if (!$this->checkTideways()) {
            $handler();
            return;
        }

        \Tideways\Profiler::start();
        try {
            $handler();
        } catch (\Throwable $e) {
            \Tideways\Profiler::logException($e);
            throw $e;
        } finally {
            \Tideways\Profiler::stop();
        }
    }

    private function checkTideways(): bool
    {
        return !class_exists('Tideways\Profiler') && !\Tideways\Profiler::isEnabled();
    }
}

@ppelisset
Copy link

I’m actually working on exactly the same thing 😅
On my side, I’m using a simple Listener with very high and very low priorities to make sure it runs first at the beginning of the request and last at the end:

class TidewaysListener
{
    #[AsEventListener(RequestEvent::class, priority: PHP_INT_MAX)]
    public function beforeRequest(RequestEvent $event): void
    {
        Profiler::start();
    }

    #[AsEventListener(event: KernelEvents::TERMINATE, priority: PHP_INT_MIN)]
    public function terminateRequest(TerminateEvent $event): void
    {
        Profiler::stop();
    }
}

From my tests, there’s no need to manually handle \Tideways\Profiler::logException — it already integrates with Symfony’s ErrorHandler natively.

@andrew-demb
Copy link

@Scarbous I'm talking about the kernel's decorator, not kernel events. It will cover the full handle process, and will be generic, not just for frankenphp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants