Skip to Content
🎉 Bref 3.0 is released. Read more →
DocumentationUpgradingFrom 3.x to 4.0

Upgrading to Bref 4.0

Updating dependencies

Update all Bref packages in your composer.json file from ^3 to ^4, for example:

composer.json
"require": { "bref/bref": "^4", "bref/laravel-bridge": "^4", // if you use Laravel "bref/symfony-bridge": "^4" // if you use Symfony }

Only update the versions for the packages you actually have in your project.

Then run:

composer update --with-all-dependencies

PHP extensions directory

Bref’s PHP extensions are now installed in /usr/local/lib/php/extensions instead of /opt/bref/extensions.

If you enable a Bref extension with its full path, use its name instead:

php/conf.d/php.ini
-extension=/opt/bref/extensions/gd.so +extension=gd

Extensions that you add yourself in /opt/bref/extensions (via an AWS Lambda layer or in your container image) are no longer found by their name: load them with their full path.

ext.ini
-extension=xhprof.so +extension=/opt/bref/extensions/xhprof.so

Location of the SSL certificates

The SSL certificates (CA bundle) are now in /etc/ssl/certs/ca-certificates.crt, their usual location on Ubuntu. The Bref v3 locations no longer exist:

  • /opt/bref/ssl/cert.pem
  • /etc/pki/tls/cert.pem

If your application references one of them, for example in MYSQL_ATTR_SSL_CA to connect to a database over SSL, replace it with /etc/ssl/certs/ca-certificates.crt. In PHP code, openssl_get_cert_locations()['default_cert_file'] returns a path that works in every Bref version.

Failed console commands are no longer retried

When a command invoked asynchronously failed (e.g. a cron), Lambda retried it twice by default. Bref now sets maximumRetryAttempts: 0 on console functions: Lambda no longer retries failed commands. Failed commands are still counted in the Errors metric of the function.

To keep the retries, set maximumRetryAttempts on the function:

serverless.yml
functions: artisan: handler: artisan runtime: php-84-console maximumRetryAttempts: 2

If you deploy without serverless.yml (e.g. with AWS CDK or Terraform), set the maximum retry attempts of the function’s asynchronous invocations to 0 to get the same behavior.

HTTP headers with an underscore are dropped

Headers with an underscore in their name (e.g. api_key) are no longer passed to PHP, on every runtime. Like api-key, they would become the HTTP_API_KEY variable: a client could replace a header set by a proxy. Nginx and Apache drop them by default.

If your application reads such a header, rename it with a dash instead (e.g. api-key), in the application and in its clients.

Work after the response with fastcgi_finish_request()

Bref layers no longer disable fastcgi_finish_request(): the client gets the response when it is called, and the rest of the script runs afterwards. Laravel and Symfony call it, then run their “terminate” work (e.g. Laravel’s defer(), Symfony’s kernel.terminate listeners) after the response.

There is nothing to change, but that work still counts toward the function’s timeout and is billed, and the Lambda instance does not handle other requests until it finishes. Read Work after the response.

Custom HTTP handlers and listeners

These changes only affect code that uses Bref’s PHP classes directly:

  • Bref\Event\Http\HttpHandler::handle() now returns a Bref\Runtime\LambdaResult instead of an array. Handlers that implement handleRequest() are not affected. Code that calls handle() directly (e.g. in tests) can read the response with json_decode($result->contents(), true).
  • afterInvoke() in Bref\Listener\BrefEventSubscriber receives that LambdaResult as $result for HTTP events, already sent to Lambda.

Network calls time out before the Lambda timeout

A network call that never answers now fails with a timeout error 2 seconds before the Lambda timeout, instead of being stopped by Lambda without any error. Bref lowers default_socket_timeout and mysqlnd.net_read_timeout to the time left in the invocation.

This covers PHP streams (e.g. file_get_contents()), Redis, Symfony HttpClient and MySQL. It does not cover curl, Guzzle (including the Laravel HTTP client and the AWS SDK) and PostgreSQL queries: set timeouts in their options.

Connecting to a MySQL, MariaDB or PostgreSQL database now times out after 20 seconds, instead of about 2 minutes when the database can’t be reached. To change it:

config/database.php
'mysql' => [ // ... 'options' => [ PDO::ATTR_TIMEOUT => 5, // seconds ], ],
Last updated on