--- breadcrumb: - What's new? - Version 3.4 summary-order: 7;96 keywords: - release - new features - "3.4" --- # What's new in 3.4 Version 3.4 lets your application keep working after the response is sent, adds the HTTP `QUERY` method, and makes queues and mail delivery safer. To upgrade, follow [Upgrading from version 3.3 to 3.4](../getting-started/upgrading.md#upgrading-from-version-33-to-34). ## Work after the response Some work does not need to delay the response: sending an email, calling a webhook, warming a cache. You can now run it after the response has been sent to the client, in the same PHP process. Terminate the application in your front controller: ```php $app = new HttpApp(); $response = $app->handle(); $app->print($response); $app->terminate(); ``` Then listen to the terminate event, or use a deferred queue. With PHP-FPM or LiteSpeed, the client does not wait for this work. See [After the response](../http/terminate.md). ## Deferred queues A deferred queue is consumed in the same process, once the response has been sent or at the end of a CLI command. No worker is needed. Declare a memory queue and list it as deferred: ```json { "berlioz": { "queues": { "queues": [ { "type": "Berlioz\\QueueManager\\Queue\\MemoryQueue", "name": "deferred", "max_attempts": 1 } ], "deferred": { "queues": ["deferred"] } } } } ``` Push jobs to it as to any other queue. The same job handlers process them, so you can move a job to a persistent queue later without changing your code. See [Deferred queues](../guides/queues.md#deferred-queues). ## HTTP QUERY method Routes accept the `QUERY` method of [RFC 10008](https://www.rfc-editor.org/info/rfc10008/): a safe and idempotent request that carries its query in the body. The `acceptQuery` route option declares the accepted formats and rejects the other ones: ```php #[Berlioz\Route('/contacts', method: ['GET', 'QUERY'], acceptQuery: ['application/json'])] public function search(ServerRequestInterface $request): array { $criteria = $request->getParsedBody() ?? $request->getQueryParams(); // ... } ``` The HTTP client gets a `Client::query()` method, and forms read the body of `QUERY` requests. See [QUERY method](../http/routing.md#query-method). ## Encrypted SMTP connections The SMTP transport supports STARTTLS and implicit TLS. Encryption is mandatory once requested: the transport never falls back to a plain connection. ```php $smtp = new Smtp( host: 'smtp.test.com', username: 'user@test.com', password: 'password', port: 587, encryption: SmtpEncryption::STARTTLS, timeout: 5, ); ``` See [SMTP connection modes](../components/mailer.md#smtp-connection-modes). ## Queues ### More queue types in the configuration Redis, AMQP, RabbitMQ and Null queues can be declared in the configuration, like database, SQS and memory queues: ```json { "type": "Berlioz\\QueueManager\\Queue\\RedisQueue", "redis": { "host": "127.0.0.1", "port": 6379 }, "name": ["emails", "notifications"] } ``` See [Redis queue](../guides/queues.md#redis-queue), [AMQP queue](../guides/queues.md#amqp-queue) and [RabbitMQ queue](../guides/queues.md#rabbitmq-queue). ### Last attempt of a job A job handler can know that the current attempt is the last one, and act differently when the job will not be retried: ```php public function handle(JobInterface $job): void { try { $this->mailer->sendOrderConfirmation($order, $email); } catch (MailerException $exception) { if ($job->isLastAttempt()) { $this->orders->flagConfirmationFailure($order); return; } throw $exception; } } ``` See [Handling the last attempt](../guides/queues.md#handling-the-last-attempt). ### Safer retries - Redis queues stop retrying a job after `maxAttempts` and no longer lose a job when a worker dies while processing it. - AMQP queues count the messages redelivered by the broker as attempts. - Every queue exposes its maximum attempts and its retry time. See [Attempts and retry time](../components/queue-manager.md#attempts-and-retry-time) and [Delivery guarantees and idempotency](../components/queue-manager.md#delivery-guarantees-and-idempotency). ## Other new features - **Forms:** `ApiDataProvider` keeps JSON types with `strictJson: true` and handles `PATCH` and `DELETE` requests. See [Data providers](../guides/forms/data-providers.md). - **Forms:** `handle($request, apply: false)` validates a submission without modifying the mapped object, and `apply()` writes it once it is valid. See [Validate before writing](../guides/forms/form.md#validate-before-writing). - **Forms:** inputs reject arrays and objects submitted as their value. See [Non-scalar values](../guides/forms/inputs.md#non-scalar-values). - **Forms:** constraints added with `invalid()` make the element and its parents invalid, until the form is handled again or `resetConstraints()` is called. See [Manual invalidation](../components/form.md#manual-invalidation). - **HTTP:** a malformed body of the incoming request, such as invalid JSON, produces a 400 Bad Request instead of a 500. See [Malformed bodies](../components/http-message.md#malformed-bodies). - **HTTP:** `HttpApp::print()` validates the complete response before sending it: an invalid status line or header is never sent halfway. See [HTTP/1 emission](../components/http-message.md#http1-emission). - **HTTP client:** the TLS client certificate and the credentials given to the cURL adapter are no longer sent when a redirect leaves the initial origin; `credentials_origins` lists the other origins allowed to receive them. See [Transport credentials](../components/http-client.md#transport-credentials). - **Controllers:** `jsonResponse()` throws a 500 error when the encoding fails, instead of returning an empty 204 response. See [Response helpers](../http/controllers.md#response-helpers). - **HTTP client:** the cURL and stream adapters use the proxy of the environment variables in the same way, and `'proxy' => false` disables it. See [Proxy](../components/http-client.md#proxy). - **Hector ORM:** PDO options accept constant names such as `PDO::ATTR_TIMEOUT`. See [PDO options](../guides/orm/hector.md#pdo-options). - **Debug:** debug access is restricted to `127.0.0.1` and `::1` by default; allow other clients with IP addresses, CIDR ranges or aliases such as `private`. See [Restrict access](../getting-started/debug.md#restrict-access). - **Debug:** the toolbar shows the response time, and the console shows a waiting page while a request still works after its response. See [Debug](../getting-started/debug.md#response-time). - **Twig:** `entrypoints()` preloads every file it renders. See [Preload](../guides/templating/twig-extensions.md#preload). - **Queue worker:** `Worker::drain()` processes a queue until it is empty. See [Drain a queue](../components/queue-manager.md#drain-a-queue). - **Queue manager:** `QueueManager::getQueue()` returns a queue by its name, for example to read its settings. See [Get a queue](../components/queue-manager.md#get-a-queue). ## Deprecations Declaring services in the `container.services` configuration key, the `scalar` option of form inputs and four other features are deprecated. See [Preparing for version 4](../getting-started/upgrading.md#preparing-for-version-4).