Skip to content

Conversation

@mnapoli
Copy link
Member

@mnapoli mnapoli commented May 24, 2025

This PR will contain all changes for Bref v3.

This will be a long-running PR, I like to keep this open for months so that we have a place to preview and discuss changes. I do not intend to merge this pull request soon.

This PR goes hand-in-hand with brefphp/aws-lambda-layers#257.

Breaking changes:

  • Dropped support for PHP 8.0 and 8.1
  • Underlying Linux upgrade -> 99% of projects should not be impacted
  • Deployment via containers: need to change because of Refactor to a single layer aws-lambda-layers#256 (docs coming soon)
  • The pgsql extension is now enabled by default
  • The small bref CLI is removed, this was already stripped down with the v2 upgrade and could only set up new projects. That built-in CLI is no longer needed. It is replaced by serverless CLI commands and the bref external CLI (https://github.com/brefphp/cli).

All changes:

Ideas considered:

TODO:

mnapoli and others added 8 commits May 24, 2025 23:42
* Switch to a single layer

* Force display_errors

* Fix tests

* Fix CS

* Upgrade documentation

* Upgrade documentation

* Upgrade documentation for containers
Co-authored-by: mnapoli <720328+mnapoli@users.noreply.github.com>
Co-authored-by: mnapoli <720328+mnapoli@users.noreply.github.com>
Co-authored-by: mnapoli <720328+mnapoli@users.noreply.github.com>
@mnapoli mnapoli marked this pull request as ready for review May 26, 2025 21:34
@mnapoli mnapoli marked this pull request as draft May 26, 2025 21:34
@aromka
Copy link

aromka commented Oct 25, 2025

Do you have any ETA in mind for this?

# Conflicts:
#	layers.json
@mnapoli
Copy link
Member Author

mnapoli commented Nov 12, 2025

Targeting end of November or early December hopefully. You can start using v3 right now, I have published the first alpha versions.

@jlabedo
Copy link

jlabedo commented Nov 12, 2025

Hello @mnapoli , thank you for your work, I am using Bref since a while and working like a charm.

But, I am about to drop bref runtime (php files) and only keep base layers for the reason that I can't send the response BEFORE calling kernel.terminate and do some heavy work (my use case is mostly sending opentelemetry data for now). I am using the function runtime (way faster than fpm because of connection reuse) and symfony.

So I built a custom runtime for symfony + bref, doing some low level things I would prefer see in Bref :)
Have you considered leveraging the symfony runtime for v3 ? I could help you and open a PR if you think it might be a good thing.

here is my http runner code, leveraging symfony runtime:

public function run(): int
    {
        $loops = 0;
        $memoryLeakDetector = new MemoryLeakDetector();

        while ($invocation = $this->apiClient->nextInvocation()) {            
            try {
                if (is_string($invocation->event)) {
                    throw new Exception('Invalid event: ' . $invocation->event);
                }
                $request = RequestConverter::convert($invocation->event);

                $response = $this->kernel->handle($request);

                $lambdaResponse = ResponseConverter::convert($response);
            } catch (Throwable $e) {
                $invocation->signalFailure($e);
                return 0;
            }
            
            $invocation->sendResponse($lambdaResponse);
            
            if ($this->kernel instanceof TerminableInterface) {
                $this->kernel->terminate($request, $response);
            }

            // Only check loop max if it's set and > 0
            if ($this->loopMax > 0 && ++$loops > $this->loopMax) {
                return 0;
            }

            // Boot kernel to prepare for next invocation (resets resettable services)
            if ($this->kernel instanceof \Symfony\Component\HttpKernel\KernelInterface) {
                $this->kernel->boot();
            }

            // Clear memory between invocations
            gc_collect_cycles();

            // Check for memory leak
            if ($memoryLeakDetector->checkAndRecord()) {
                return 0;
            }
        }
    }

@mnapoli
Copy link
Member Author

mnapoli commented Nov 12, 2025

@jlabedo I think this already exists: https://bref.sh/docs/symfony/keep-alive right?

(PS: can you create a separate issue if this isn't it, to avoid cluttering the v3 PR)

This was referenced Dec 2, 2025
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