jdecool/scaleway-runtimepublic Fork
⑂ 4951903
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

docs: write the full READMEUnverified

Covers installation, configuration, the supported Application types, CRON
triggers and Command Invocations, packaging, deployment, the Emulator, Warm
Process semantics, and the limitations and platform facts still unverified.
Jérémy DECOOL committed 2026-11-14T02:22:42+01:00 Browse files
4951903 parent: cf7d882
modified README.md +458 -22
@@ -1,41 +1,477 @@
11 # Scaleway Runtime
22
3-A [Symfony Runtime](https://symfony.com/doc/current/components/runtime.html) that runs Symfony and PHP applications on [Scaleway Serverless Functions](https://www.scaleway.com/en/serverless-functions/) (PHP runtimes `php84` and `php85`).
3+A [Symfony Runtime](https://symfony.com/doc/current/components/runtime.html) that runs Symfony and PHP applications on [Scaleway Serverless Functions](https://www.scaleway.com/en/serverless-functions/).
44
5-## Status
5+Scaleway calls a PHP function `handle($event, $context)` for each Invocation.
6+This package provides that function, boots your unchanged `public/index.php` once per Warm Process, turns each Event into a Symfony `Request` and each `Response` back into a Function Response.
7+It also ships the tools to package the function and to run it locally.
68
7-Work in progress: not usable yet.
8-See the [implementation plan](docs/plan.md) for the design and the roadmap, and the [example application](example) for a working setup.
9+Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOSSARY.md), design decisions in [docs/adr](docs/adr).
910
10-## Tools
11+> [!IMPORTANT]
12+> The runtime has only been run locally, through the Emulator.
13+> Several platform facts it relies on are still assumptions, see [Unverified platform facts](#unverified-platform-facts).
1114
12-- `vendor/bin/scaleway-init` writes the `handler.php` stub at the application root; commit it and set the function handler to `handler.handle`.
13- It refuses to replace a different `handler.php` unless run with `--force`.
14-- `vendor/bin/scaleway-package [function.zip]` builds the deployment zip: a copy of the application without local, test and secret files (see `Packager::EXCLUDES`), production dependencies installed from `composer.lock` with an authoritative class map, and the prod cache warmed up by `bin/console cache:warmup`.
15- It needs the `zip` PHP extension and `composer` on the `PATH`, and warns when the zip exceeds Scaleway's limits (100 MiB zipped, 500 MiB unzipped).
16-- `vendor/bin/scaleway-serve [127.0.0.1:8000]` starts the Emulator: each HTTP request becomes an Event passed to the application's `handle()`, and the Function Response becomes the HTTP response.
17- A CRON Invocation is simulated with a `POST /` carrying the trigger's arguments as JSON body, a Command Invocation by starting the Emulator with `SCALEWAY_CRON_SECRET` set and sending its body the same way.
15+## Contents
1816
19-The Emulator runs `handle()` in one long-lived PHP process, as a Warm Process on Scaleway: code changes need a restart, and a crashed process is replaced by a fresh one.
20-PHP's built-in server alone could not do this, since it keeps its process but wipes all PHP state after each request.
21-How Scaleway fills `X-Forwarded-*`, folds repeated query keys and names headers is still assumed.
17+- [Requirements](#requirements)
18+- [Installation](#installation)
19+- [Configuration](#configuration)
20+- [Supported Applications](#supported-applications)
21+- [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations)
22+- [Packaging](#packaging)
23+- [Deployment](#deployment)
24+- [Local development with the Emulator](#local-development-with-the-emulator)
25+- [Warm Processes](#warm-processes)
26+- [Limitations and platform caveats](#limitations-and-platform-caveats)
27+- [Contributing](#contributing)
2228
23-## CRON triggers and console commands
29+## Requirements
30+
31+- The Scaleway PHP runtimes `php84` or `php85` (PHP 8.4 or later).
32+- Symfony 7.4 or 8.x components (`symfony/runtime`, `symfony/http-kernel`, `symfony/http-foundation`).
33+- To build the deployment zip: the `zip` PHP extension and `composer` on the `PATH`.
34+- macOS or Linux for the packaging and Emulator tools (see [Windows](#windows)).
35+
36+## Installation
37+
38+```sh
39+composer require jdecool/scaleway-runtime
40+vendor/bin/scaleway-init
41+```
42+
43+`scaleway-init` writes `handler.php` at the root of your application:
44+
45+```php
46+<?php
47+
48+require __DIR__.'/vendor/autoload.php';
49+
50+function handle(array $event, mixed $context): array
51+{
52+ return JDecool\ScalewayRuntime\Handler::handle($event, $context);
53+}
54+```
55+
56+Commit it.
57+`scaleway-init` refuses to replace a `handler.php` that differs from this stub, unless run with `--force`.
58+
59+Your Front Controller stays as it is, `require_once dirname(__DIR__).'/vendor/autoload_runtime.php'` included.
60+That file is generated by the `symfony/runtime` Composer plugin, so the plugin must be allowed (`config.allow-plugins.symfony/runtime`), as Symfony Flex applications already do.
61+The Handler has already loaded `vendor/autoload.php` when the Front Controller runs, so `autoload_runtime.php` returns early and the runtime of this package takes over.
62+
63+## Configuration
64+
65+### Function handler
66+
67+Set the handler of the Scaleway function to `handler.handle`.
68+
69+### Front Controller
70+
71+The Front Controller defaults to `public/index.php`, relative to the project dir.
72+Choose another one with the `front_controller` runtime option, in `composer.json`:
73+
74+```json
75+{
76+ "extra": {
77+ "runtime": {
78+ "front_controller": "public/api.php"
79+ }
80+ }
81+}
82+```
83+
84+Or with the `APP_RUNTIME_OPTIONS` environment variable, a JSON object that wins over `extra.runtime`:
85+
86+```sh
87+APP_RUNTIME_OPTIONS='{"front_controller":"bin/console"}'
88+```
89+
90+The other `SymfonyRuntime` options (`project_dir`, `env_var_name`, `dotenv_path`...) work as usual.
91+`extra.runtime.class` and `APP_RUNTIME` are ignored: they name the runtime the same application uses elsewhere (FPM, FrankenPHP), and the Handler always uses `JDecool\ScalewayRuntime\ScalewayRuntime`.
92+
93+### Environment variables
94+
95+Set these on the function, in production:
96+
97+| Variable | Kind | Why |
98+| --- | --- | --- |
99+| `APP_ENV=prod` | Plain | Without it the application runs in `dev`, see below. |
100+| `APP_SECRET` | Secret | Symfony's `kernel.secret`, used to sign URLs, cookies and CSRF tokens. |
101+| `SCALEWAY_CRON_SECRET` | Secret | Only to run console commands from CRON triggers, see [Command Invocations](#command-invocations). |
102+
103+> [!WARNING]
104+> The `.env` file is shipped in the zip, and the one Symfony generates says `APP_ENV=dev`.
105+> Without an `APP_ENV` variable on the function, the application therefore runs with `APP_ENV=dev` and debug enabled, and shows stack traces to anyone.
106+> On a read-only code directory it is even worse: the dev container cannot be built next to the prod one warmed in the zip, so every Invocation answers a 500 whose body is the full stack trace, file paths included.
107+
108+Real environment variables win over `.env` files, as usual with Symfony's Dotenv.
109+`.env.local`, `.env.local.php` and `.env.*.local` are never shipped.
110+
111+### Writable directories
112+
113+The deployed code may be read-only.
114+When the project's `var/` directory (or the project dir, without `var/`) is not writable, the runtime sets, unless your application already did:
115+
116+- `APP_BUILD_DIR` to `var/cache`, so the container warmed in the zip is used as is;
117+- `APP_CACHE_DIR` to `<temp dir>/cache` and `APP_LOG_DIR` to `<temp dir>/log`.
118+
119+Kernels using `MicroKernelTrait` read these variables.
120+Other Kernels must override `getCacheDir()`, `getBuildDir()` and `getLogDir()` themselves.
121+Logs written to files are lost with the instance: send them to `php://stderr` instead, which the runtime also uses for its own errors.
122+
123+### Errors
124+
125+An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr and answered with a 500.
126+Its body is `Internal Server Error`, or the full exception when `APP_DEBUG` is true.
127+A Kernel that failed to boot is built again from scratch on the next Invocation.
128+
129+## Supported Applications
130+
131+The Front Controller returns a closure, as with any Symfony Runtime.
132+The type of what that closure returns, the Application, decides how Invocations are served.
133+
134+### HttpKernel
135+
136+The usual Symfony Front Controller:
137+
138+```php
139+<?php // public/index.php
140+
141+use App\Kernel;
142+
143+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
144+
145+return function (array $context) {
146+ return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
147+};
148+```
149+
150+The Kernel is booted once per Warm Process and serves every Invocation, see [Warm Processes](#warm-processes).
151+Any `HttpKernelInterface` works; a `KernelInterface` also runs [Command Invocations](#command-invocations).
152+
153+### Response
154+
155+A closure returning a `Response` is called again for every Invocation, without any Kernel.
156+A `Request` argument receives the Invocation's Request:
157+
158+```php
159+<?php // public/hello.php
160+
161+use Symfony\Component\HttpFoundation\JsonResponse;
162+use Symfony\Component\HttpFoundation\Request;
163+
164+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
165+
166+return static function (Request $request): JsonResponse {
167+ return new JsonResponse(['message' => sprintf('Hello %s!', $request->query->get('name', 'World'))]);
168+};
169+```
170+
171+Keep the closure cheap, as it runs on every Invocation, and make it return a `Response` every time.
172+See [ADR 0004](docs/adr/0004-call-response-front-controllers-per-invocation.md).
173+
174+### PSR-15 request handler
175+
176+A closure returning a `Psr\Http\Server\RequestHandlerInterface` builds it once per Warm Process.
177+It needs two more packages:
178+
179+```sh
180+composer require symfony/psr-http-message-bridge nyholm/psr7
181+```
182+
183+```php
184+<?php // public/index.php
185+
186+use App\ApiHandler;
187+use Psr\Http\Server\RequestHandlerInterface;
188+
189+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
190+
191+return static fn (): RequestHandlerInterface => new ApiHandler();
192+```
193+
194+The PSR-7 request carries the client address, scheme, host and port resolved from the platform's `X-Forwarded-*` headers, in its URI and in the `REMOTE_ADDR`, `HTTPS`, `HTTP_HOST` and `SERVER_PORT` server params.
195+A handler implementing `Symfony\Contracts\Service\ResetInterface` is reset before every Invocation but the first.
196+A malformed `Host` or `X-Forwarded-Host` is answered with a 400 before reaching the handler.
197+
198+### Console Application or Command
199+
200+A Front Controller returning a Console `Application` or a `Command` only serves [Command Invocations](#command-invocations), and answers every other Invocation with a 403.
201+Symfony's `bin/console` is such a Front Controller:
202+
203+```sh
204+APP_RUNTIME_OPTIONS='{"front_controller":"bin/console"}'
205+```
206+
207+A single `Command` runs whatever `command` the Command Invocation names:
208+
209+```php
210+<?php // bin/cleanup.php
211+
212+use Symfony\Component\Console\Command\Command;
213+use Symfony\Component\Console\Input\InputInterface;
214+use Symfony\Component\Console\Output\OutputInterface;
215+
216+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
217+
218+return static fn (): Command => (new Command('app:cleanup'))
219+ ->setCode(static function (InputInterface $input, OutputInterface $output): int {
220+ $output->writeln('Cleaned up');
221+
222+ return Command::SUCCESS;
223+ });
224+```
225+
226+This needs `symfony/console`, and `symfony/framework-bundle` for a `Symfony\Bundle\FrameworkBundle\Console\Application`.
227+
228+### Raw callable
229+
230+A closure returning another `Closure` talks to Scaleway without any translation.
231+The inner closure is built once per Warm Process and receives every Event and context as they are, CRON Invocations included:
232+
233+```php
234+<?php // public/raw.php
235+
236+return static fn (): Closure => static fn (array $event, mixed $context): array => [
237+ 'statusCode' => 200,
238+ 'headers' => ['Content-Type' => 'text/plain'],
239+ 'body' => 'Hello from '.($event['path'] ?? '/'),
240+];
241+```
242+
243+It must return a Function Response: an int `statusCode`, optional `headers` mapping names to a string or a list of strings, a string `body` and an optional bool `isBase64Encoded`.
244+Other keys are dropped, and any other return value fails the Invocation with a 500.
245+Command Invocations are not routed: the raw callable gets their Event like any other.
246+An invokable object is not taken for a raw callable; return `$object(...)` to make it one.
247+
248+## CRON triggers and Command Invocations
249+
250+### CRON triggers
24251
25252 A CRON trigger calls the Application with a `POST /` whose JSON body holds the trigger's arguments.
26-To run a console command instead, set a random `SCALEWAY_CRON_SECRET` as a secret environment variable of the function (for instance `openssl rand -hex 32`), and give the trigger these arguments:
253+With a Kernel, handle it like any route:
254+
255+```php
256+#[Route('/', methods: ['POST'])]
257+public function cron(Request $request): Response
258+{
259+ $args = $request->toArray(); // the trigger's arguments
260+ // ...
261+}
262+```
263+
264+### Command Invocations
265+
266+A CRON trigger may run a console command instead, through the Console Application of the same Kernel.
267+
268+1. Generate a random secret, for instance with `openssl rand -hex 32`.
269+2. Set it as the `SCALEWAY_CRON_SECRET` secret environment variable of the function.
270+3. Give the CRON trigger these arguments:
27271
28272 ```json
29273 {"command": "app:sync", "args": {"source": "s3", "--force": true, "--tag": ["a", "b"]}, "secret": "<SCALEWAY_CRON_SECRET>"}
30274 ```
31275
32-`args` maps argument names, and option names with their dashes, to values, as Symfony's `ArrayInput` does; the command runs without interaction, through the Console Application of the same Kernel.
33-Exit code 0 answers a 200 and any other exit code a 500, both with the command output as plain text body; a failure is also logged to stderr with that output.
34-Without the variable, or with another secret, the body is a plain HTTP body and reaches `POST /`: an HTTP client cannot run commands without knowing the secret (see [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md)).
276+`args` is optional, and maps argument names, and option names with their dashes, to values, as Symfony's `ArrayInput` does.
277+The command runs without interaction: questions get their default answer.
278+Services are reset around each command, so it shares no state with the Invocations before and after it.
279+
280+| Outcome | Function Response |
281+| --- | --- |
282+| Exit code 0 | 200, the command output as plain text body |
283+| Any other exit code | 500, the command output as plain text body, also logged to stderr |
284+| `args` not a JSON object | 500 |
285+| The Front Controller returns a Response, a PSR-15 handler or a plain `HttpKernelInterface` | 500, as there is no Console Application to run the command |
286+
287+### Security model
288+
289+Nothing known in an Event tells a CRON Invocation from an HTTP one, so any internet client can send a body naming a command to a public function.
290+A body only becomes a Command Invocation when its `secret` matches `SCALEWAY_CRON_SECRET`, compared in constant time.
291+Otherwise the body reaches the Application as a plain HTTP body on `POST /`, and a body carrying a wrong `secret` is logged (without its value).
292+Without `SCALEWAY_CRON_SECRET`, or with an empty one, Command Invocations are off.
293+
294+Keep in mind that:
295+
296+- the secret is stored in clear in the trigger's arguments, readable by anyone who can read the function's triggers or the Terraform state;
297+- rotating it means updating the variable and every CRON trigger together.
298+
299+See [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md) for the alternatives considered.
300+
301+## Packaging
302+
303+```sh
304+vendor/bin/scaleway-package [function.zip]
305+```
306+
307+It builds the deployment zip in a private temporary directory, removed afterwards whatever happens:
308+
309+1. It copies the application, without the excluded files below and without the zip being written.
310+2. It runs `composer install --no-dev --classmap-authoritative` from the committed `composer.lock`, with `APP_ENV=prod` and `APP_DEBUG=0`.
311+ Relative `path` repositories are resolved against your application, and mirrored instead of symlinked.
312+3. It runs `bin/console cache:warmup`, when `bin/console` exists, to ship a warmed prod cache.
313+4. It zips the result, keeping the executable bits, and the `composer.lock` exactly as committed.
314+
315+It requires a committed `composer.lock`, for reproducible builds, and `handler.php`.
316+Symbolic links are followed: their target is copied.
317+
318+| Shipped | Not shipped |
319+| --- | --- |
320+| Your code, `composer.json`, `composer.lock`, `handler.php` | `vendor/` and `var/` from your machine (rebuilt) |
321+| `vendor/` without dev dependencies | `tests/`, `phpunit.xml(.dist)`, `.phpunit.cache`, `.phpunit.result.cache`, `.php-cs-fixer.cache` |
322+| `var/cache/prod`, warmed | `.env.local`, `.env.local.php`, `.env.*.local` |
323+| `.env`, `.env.prod`... as they are | `.git`, `.idea`, `.vscode`, `.DS_Store`, `node_modules` anywhere |
324+| | `.terraform`, `*.tfstate`, `*.tfstate.*` anywhere (Terraform state holds secrets in clear) |
325+
326+The full list is `Packager::EXCLUDES` in [src/Packager.php](src/Packager.php).
327+`--classmap-authoritative` means only classes known at build time can be autoloaded.
328+
329+Scaleway accepts zips up to 100 MiB, and up to 500 MiB of unzipped code ([limits](https://www.scaleway.com/en/docs/serverless-functions/reference-content/functions-limitations/)).
330+`scaleway-package` warns when the zip exceeds either, but still writes it.
331+
332+## Deployment
333+
334+[example/terraform](example/terraform/main.tf) deploys the [example application](example) with its `php85` runtime, `handler.handle`, `APP_ENV=prod`, the `APP_SECRET` and `SCALEWAY_CRON_SECRET` secrets, a CRON trigger calling `POST /` and one running a command.
335+Its [README](example/README.md#deploy-it) gives the commands.
336+That Terraform code was written against the `scaleway/scaleway` provider v2.92 documentation and has never been applied.
337+
338+Redeploy by running `scaleway-package` again, then `terraform apply`.
339+
340+## Local development with the Emulator
341+
342+```sh
343+vendor/bin/scaleway-serve [127.0.0.1:8000]
344+```
345+
346+The Emulator turns each HTTP request into an Event, calls your `handle()` and turns the Function Response back into the HTTP response.
347+`handle()` runs in one long-lived PHP process, as in a Warm Process: restart the Emulator after changing code.
348+A crashed process is replaced by a fresh one, as Scaleway starts a new instance.
349+
350+PHP's built-in server receives the requests, and forwards the Events to that process over a Unix socket in a private temporary directory.
351+The context passed to `handle()` is an empty array.
352+
353+The Event is built the way the platform is assumed to build it:
354+
355+- header names in `Title-Case`, repeated headers joined with `, `;
356+- the client address appended to `X-Forwarded-For`, and `X-Forwarded-Proto: http`;
357+- `queryStringParameters` as a map of strings, the last value of a repeated key winning;
358+- bodies that are not valid UTF-8 base64-encoded, with `isBase64Encoded: true`.
359+
360+Simulate a CRON trigger with a `POST /` carrying its arguments as JSON body:
361+
362+```sh
363+curl -X POST http://127.0.0.1:8000/ -H 'Content-Type: application/json' --data '{"job": "cleanup"}'
364+```
365+
366+Simulate a Command Invocation by starting the Emulator with `SCALEWAY_CRON_SECRET` set, and sending the [Command Invocation body](#command-invocations) the same way:
367+
368+```sh
369+SCALEWAY_CRON_SECRET=local-secret vendor/bin/scaleway-serve
370+curl -X POST http://127.0.0.1:8000/ --data '{"command": "app:greet", "args": {"name": "Scaleway"}, "secret": "local-secret"}'
371+```
372+
373+To run exactly what gets deployed, serve the packaged zip from a read-only copy:
374+
375+```sh
376+vendor/bin/scaleway-package
377+unzip -q function.zip -d /tmp/function && chmod -R a-w /tmp/function
378+APP_ENV=prod APP_SECRET=local php /tmp/function/vendor/bin/scaleway-serve
379+```
380+
381+## Warm Processes
382+
383+The Application is built once per Warm Process and reused by the following Invocations, like with FrankenPHP's worker mode or RoadRunner ([ADR 0002](docs/adr/0002-reuse-application-across-invocations.md)).
384+If Scaleway does not keep processes warm, this degrades to one boot per Invocation.
385+
386+Between Invocations, for a Kernel:
387+
388+- `terminate()` runs after each Invocation, and a failure in it is logged without changing the Function Response;
389+- the `services_resetter` resets the services tagged `kernel.reset` before the next request, as Symfony's Kernel does;
390+- uploaded files are deleted, and output buffers the Application left open are closed.
391+
392+Everything else survives, so your application must be safe for long-running execution:
393+
394+- do not keep per-request state in static properties or in services that do not implement `ResetInterface`;
395+- in-memory caches and collections grow across Invocations unless reset;
396+- connections (database, HTTP clients) may have been closed by the server while the process was idle;
397+- `exit()` or a fatal error ends the process, and the next Invocation pays a cold start.
398+
399+## Limitations and platform caveats
400+
401+### Requests and responses
402+
403+- **Superglobals**: `$_GET`, `$_POST`, `$_COOKIE`, `$_FILES` and the request entries of `$_SERVER` (`REQUEST_URI`, `HTTP_*`...) are not populated per Invocation.
404+ Read the `Request` object instead; `Request::createFromGlobals()` does not describe the Invocation.
405+- **Output**: only the returned `Response` reaches the client.
406+ `echo` outside the Response, `header()` and `http_response_code()` do not.
407+- **Query strings**: the Event carries `queryStringParameters` as a map, so a repeated key such as `a=1&a=2`, or `tags[]=a&tags[]=b`, likely reaches the Application with one value only.
408+ Keys are then parsed like PHP does, so `a.b` becomes `a_b` and `a[b]` nests.
409+- **Form bodies**: `application/x-www-form-urlencoded` bodies are parsed for `POST`, `PUT`, `DELETE`, `PATCH` and `QUERY`, `multipart/form-data` only for `POST`, as PHP does.
410+ Uploaded files are `UploadedFile` objects in test mode: `move()` works, `is_uploaded_file()` does not.
411+- **Cookies**: request cookie names are taken verbatim: unlike PHP's `$_COOKIE`, dots and spaces are not turned into underscores and `a[b]` does not nest.
412+- **Streaming**: `StreamedResponse` and `BinaryFileResponse` are buffered into one Function Response; Server-Sent Events and long downloads are not possible.
413+ Bodies that are not valid UTF-8 are sent base64-encoded.
414+- **PSR-15 responses** go through Symfony's `Response`, which adds `Cache-Control: no-cache, private` and `Date` when they are missing.
415+- **HEAD requests**: only FrameworkBundle's `ResponseListener` strips the body of a `HEAD` response.
416+ A bare `HttpKernelInterface`, a Response Front Controller or a PSR-15 handler returns the full body, unless it handles `HEAD` itself.
417+- **Request size**: Scaleway documents a 6 MiB limit for request bodies.
418+
419+### Client IP and trusted proxies
420+
421+The `Request` always sees `127.0.0.1` as its peer, standing for the platform proxy, which the runtime trusts for `X-Forwarded-For`, `-Host`, `-Port` and `-Proto`.
422+If your application configures its own trusted proxies (`framework.trusted_proxies`), the runtime leaves them alone: include `127.0.0.1`, or `getClientIp()`, `getHost()` and `isSecure()` will ignore the platform's headers.
423+
424+> [!CAUTION]
425+> Whether Scaleway overwrites, appends to or passes through the `X-Forwarded-*` headers a client sends is not verified yet.
426+> If it passes them through, a client can choose the IP returned by `getClientIp()` and the host used to generate absolute URLs.
427+> Do not rely on them for access control or rate limiting until the probe settles it.
428+
429+### Composer at deploy time
430+
431+Scaleway documents that it installs the dependencies of a shipped `composer.json` at deploy time.
432+Whether it does so over the shipped `vendor/` is not verified: if it does, a `composer.lock` installing packages from a `path` repository outside the zip, as the example's does, likely fails the deployment.
433+
434+### Windows
435+
436+`scaleway-serve` and `scaleway-package` rely on Unix sockets and `/dev/null`: they run on macOS and Linux, not on Windows outside WSL.
437+Without the `pcntl` extension, stopping the Emulator with `kill` may leave its PHP processes running.
438+
439+### Unverified platform facts
440+
441+The runtime and the Emulator rely on these, still unmeasured on Scaleway.
442+The [probe function](probe) measures each of them; until its results are folded into this README, treat them as assumptions.
443+
444+- The CRON Event shape: a `POST /` whose body is the trigger's arguments as JSON, and whether it carries a marker HTTP clients cannot forge.
445+- That processes are kept warm between Invocations.
446+- How `X-Forwarded-*` headers sent by clients are handled.
447+- How repeated query keys are folded, and the case of header names.
448+- That multi-value response headers (lists, as for several `Set-Cookie`) are sent as repeated headers.
449+- When request bodies are base64-encoded, and the actual body size limit.
450+- The Content-Type added to responses without one, and how binary responses are served.
451+- The type and content of `$context`.
452+- That plain and secret environment variables reach `$_SERVER`, where `APP_RUNTIME_OPTIONS`, `APP_ENV` and `APP_DEBUG` are read.
453+- That the code directory is read-only and `/tmp` writable.
454+- Whether Composer runs over the shipped `vendor/` at deploy time.
455+- Where stdout, stderr and uncaught exceptions go.
456+
457+## Contributing
458+
459+```sh
460+composer install
461+composer check # PHP-CS-Fixer (dry run), PHPStan (max level) and PHPUnit
462+composer cs-fix # applies the coding style
463+```
464+
465+CI runs `composer validate --strict` and `composer check` on PHP 8.4 and 8.5, each against Symfony 7.4 and 8.x, the whole Symfony stack being pinned through Flex's `SYMFONY_REQUIRE`.
466+It also packages the [example application](example), serves its zip read-only in prod through the Emulator, and runs its [end-to-end scenarios](example/e2e/run.sh).
467+
468+The repository holds:
35469
36-A Front Controller may also return a Console `Application` or a `Command`, as with SymfonyRuntime: the function then only runs Command Invocations, and answers any other Invocation with a 403.
37-A single `Command` runs whatever `command` the arguments name.
38-Running commands needs `symfony/console`, and `symfony/framework-bundle` for a Kernel.
470+- `src/`, `bin/`, `resources/`: the package;
471+- `tests/`: PHPUnit tests, packaging included (it runs Composer, offline);
472+- `example/`: a demo Symfony application consuming the package through a `path` repository, with Terraform code to deploy it;
473+- `probe/`: a dependency-free function measuring the open platform facts;
474+- `docs/`: the [implementation plan](docs/plan.md) and the [ADRs](docs/adr).
39475
40476 ## License
41477
@@ -1,41 +1,477 @@
1 # Scaleway Runtime1 # Scaleway Runtime
2 2
3-A [Symfony Runtime](https://symfony.com/doc/current/components/runtime.html) that runs Symfony and PHP applications on [Scaleway Serverless Functions](https://www.scaleway.com/en/serverless-functions/) (PHP runtimes `php84` and `php85`).3+A [Symfony Runtime](https://symfony.com/doc/current/components/runtime.html) that runs Symfony and PHP applications on [Scaleway Serverless Functions](https://www.scaleway.com/en/serverless-functions/).
4 4
5-## Status5+Scaleway calls a PHP function `handle($event, $context)` for each Invocation.
6+This package provides that function, boots your unchanged `public/index.php` once per Warm Process, turns each Event into a Symfony `Request` and each `Response` back into a Function Response.
7+It also ships the tools to package the function and to run it locally.
6 8
7-Work in progress: not usable yet.9+Vocabulary (Invocation, Event, Warm Process...) is defined in [GLOSSARY.md](GLOSSARY.md), design decisions in [docs/adr](docs/adr).
8-See the [implementation plan](docs/plan.md) for the design and the roadmap, and the [example application](example) for a working setup.
9 10
10-## Tools11+> [!IMPORTANT]
12+> The runtime has only been run locally, through the Emulator.
13+> Several platform facts it relies on are still assumptions, see [Unverified platform facts](#unverified-platform-facts).
11 14
12-- `vendor/bin/scaleway-init` writes the `handler.php` stub at the application root; commit it and set the function handler to `handler.handle`.15+## Contents
13- It refuses to replace a different `handler.php` unless run with `--force`.
14-- `vendor/bin/scaleway-package [function.zip]` builds the deployment zip: a copy of the application without local, test and secret files (see `Packager::EXCLUDES`), production dependencies installed from `composer.lock` with an authoritative class map, and the prod cache warmed up by `bin/console cache:warmup`.
15- It needs the `zip` PHP extension and `composer` on the `PATH`, and warns when the zip exceeds Scaleway's limits (100 MiB zipped, 500 MiB unzipped).
16-- `vendor/bin/scaleway-serve [127.0.0.1:8000]` starts the Emulator: each HTTP request becomes an Event passed to the application's `handle()`, and the Function Response becomes the HTTP response.
17- A CRON Invocation is simulated with a `POST /` carrying the trigger's arguments as JSON body, a Command Invocation by starting the Emulator with `SCALEWAY_CRON_SECRET` set and sending its body the same way.
18 16
19-The Emulator runs `handle()` in one long-lived PHP process, as a Warm Process on Scaleway: code changes need a restart, and a crashed process is replaced by a fresh one.17+- [Requirements](#requirements)
20-PHP's built-in server alone could not do this, since it keeps its process but wipes all PHP state after each request.18+- [Installation](#installation)
21-How Scaleway fills `X-Forwarded-*`, folds repeated query keys and names headers is still assumed.19+- [Configuration](#configuration)
20+- [Supported Applications](#supported-applications)
21+- [CRON triggers and Command Invocations](#cron-triggers-and-command-invocations)
22+- [Packaging](#packaging)
23+- [Deployment](#deployment)
24+- [Local development with the Emulator](#local-development-with-the-emulator)
25+- [Warm Processes](#warm-processes)
26+- [Limitations and platform caveats](#limitations-and-platform-caveats)
27+- [Contributing](#contributing)
22 28
23-## CRON triggers and console commands29+## Requirements
30+
31+- The Scaleway PHP runtimes `php84` or `php85` (PHP 8.4 or later).
32+- Symfony 7.4 or 8.x components (`symfony/runtime`, `symfony/http-kernel`, `symfony/http-foundation`).
33+- To build the deployment zip: the `zip` PHP extension and `composer` on the `PATH`.
34+- macOS or Linux for the packaging and Emulator tools (see [Windows](#windows)).
35+
36+## Installation
37+
38+```sh
39+composer require jdecool/scaleway-runtime
40+vendor/bin/scaleway-init
41+```
42+
43+`scaleway-init` writes `handler.php` at the root of your application:
44+
45+```php
46+<?php
47+
48+require __DIR__.'/vendor/autoload.php';
49+
50+function handle(array $event, mixed $context): array
51+{
52+ return JDecool\ScalewayRuntime\Handler::handle($event, $context);
53+}
54+```
55+
56+Commit it.
57+`scaleway-init` refuses to replace a `handler.php` that differs from this stub, unless run with `--force`.
58+
59+Your Front Controller stays as it is, `require_once dirname(__DIR__).'/vendor/autoload_runtime.php'` included.
60+That file is generated by the `symfony/runtime` Composer plugin, so the plugin must be allowed (`config.allow-plugins.symfony/runtime`), as Symfony Flex applications already do.
61+The Handler has already loaded `vendor/autoload.php` when the Front Controller runs, so `autoload_runtime.php` returns early and the runtime of this package takes over.
62+
63+## Configuration
64+
65+### Function handler
66+
67+Set the handler of the Scaleway function to `handler.handle`.
68+
69+### Front Controller
70+
71+The Front Controller defaults to `public/index.php`, relative to the project dir.
72+Choose another one with the `front_controller` runtime option, in `composer.json`:
73+
74+```json
75+{
76+ "extra": {
77+ "runtime": {
78+ "front_controller": "public/api.php"
79+ }
80+ }
81+}
82+```
83+
84+Or with the `APP_RUNTIME_OPTIONS` environment variable, a JSON object that wins over `extra.runtime`:
85+
86+```sh
87+APP_RUNTIME_OPTIONS='{"front_controller":"bin/console"}'
88+```
89+
90+The other `SymfonyRuntime` options (`project_dir`, `env_var_name`, `dotenv_path`...) work as usual.
91+`extra.runtime.class` and `APP_RUNTIME` are ignored: they name the runtime the same application uses elsewhere (FPM, FrankenPHP), and the Handler always uses `JDecool\ScalewayRuntime\ScalewayRuntime`.
92+
93+### Environment variables
94+
95+Set these on the function, in production:
96+
97+| Variable | Kind | Why |
98+| --- | --- | --- |
99+| `APP_ENV=prod` | Plain | Without it the application runs in `dev`, see below. |
100+| `APP_SECRET` | Secret | Symfony's `kernel.secret`, used to sign URLs, cookies and CSRF tokens. |
101+| `SCALEWAY_CRON_SECRET` | Secret | Only to run console commands from CRON triggers, see [Command Invocations](#command-invocations). |
102+
103+> [!WARNING]
104+> The `.env` file is shipped in the zip, and the one Symfony generates says `APP_ENV=dev`.
105+> Without an `APP_ENV` variable on the function, the application therefore runs with `APP_ENV=dev` and debug enabled, and shows stack traces to anyone.
106+> On a read-only code directory it is even worse: the dev container cannot be built next to the prod one warmed in the zip, so every Invocation answers a 500 whose body is the full stack trace, file paths included.
107+
108+Real environment variables win over `.env` files, as usual with Symfony's Dotenv.
109+`.env.local`, `.env.local.php` and `.env.*.local` are never shipped.
110+
111+### Writable directories
112+
113+The deployed code may be read-only.
114+When the project's `var/` directory (or the project dir, without `var/`) is not writable, the runtime sets, unless your application already did:
115+
116+- `APP_BUILD_DIR` to `var/cache`, so the container warmed in the zip is used as is;
117+- `APP_CACHE_DIR` to `<temp dir>/cache` and `APP_LOG_DIR` to `<temp dir>/log`.
118+
119+Kernels using `MicroKernelTrait` read these variables.
120+Other Kernels must override `getCacheDir()`, `getBuildDir()` and `getLogDir()` themselves.
121+Logs written to files are lost with the instance: send them to `php://stderr` instead, which the runtime also uses for its own errors.
122+
123+### Errors
124+
125+An exception escaping the Application (a Kernel failing to boot, an unsupported Front Controller...) is logged to stderr and answered with a 500.
126+Its body is `Internal Server Error`, or the full exception when `APP_DEBUG` is true.
127+A Kernel that failed to boot is built again from scratch on the next Invocation.
128+
129+## Supported Applications
130+
131+The Front Controller returns a closure, as with any Symfony Runtime.
132+The type of what that closure returns, the Application, decides how Invocations are served.
133+
134+### HttpKernel
135+
136+The usual Symfony Front Controller:
137+
138+```php
139+<?php // public/index.php
140+
141+use App\Kernel;
142+
143+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
144+
145+return function (array $context) {
146+ return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
147+};
148+```
149+
150+The Kernel is booted once per Warm Process and serves every Invocation, see [Warm Processes](#warm-processes).
151+Any `HttpKernelInterface` works; a `KernelInterface` also runs [Command Invocations](#command-invocations).
152+
153+### Response
154+
155+A closure returning a `Response` is called again for every Invocation, without any Kernel.
156+A `Request` argument receives the Invocation's Request:
157+
158+```php
159+<?php // public/hello.php
160+
161+use Symfony\Component\HttpFoundation\JsonResponse;
162+use Symfony\Component\HttpFoundation\Request;
163+
164+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
165+
166+return static function (Request $request): JsonResponse {
167+ return new JsonResponse(['message' => sprintf('Hello %s!', $request->query->get('name', 'World'))]);
168+};
169+```
170+
171+Keep the closure cheap, as it runs on every Invocation, and make it return a `Response` every time.
172+See [ADR 0004](docs/adr/0004-call-response-front-controllers-per-invocation.md).
173+
174+### PSR-15 request handler
175+
176+A closure returning a `Psr\Http\Server\RequestHandlerInterface` builds it once per Warm Process.
177+It needs two more packages:
178+
179+```sh
180+composer require symfony/psr-http-message-bridge nyholm/psr7
181+```
182+
183+```php
184+<?php // public/index.php
185+
186+use App\ApiHandler;
187+use Psr\Http\Server\RequestHandlerInterface;
188+
189+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
190+
191+return static fn (): RequestHandlerInterface => new ApiHandler();
192+```
193+
194+The PSR-7 request carries the client address, scheme, host and port resolved from the platform's `X-Forwarded-*` headers, in its URI and in the `REMOTE_ADDR`, `HTTPS`, `HTTP_HOST` and `SERVER_PORT` server params.
195+A handler implementing `Symfony\Contracts\Service\ResetInterface` is reset before every Invocation but the first.
196+A malformed `Host` or `X-Forwarded-Host` is answered with a 400 before reaching the handler.
197+
198+### Console Application or Command
199+
200+A Front Controller returning a Console `Application` or a `Command` only serves [Command Invocations](#command-invocations), and answers every other Invocation with a 403.
201+Symfony's `bin/console` is such a Front Controller:
202+
203+```sh
204+APP_RUNTIME_OPTIONS='{"front_controller":"bin/console"}'
205+```
206+
207+A single `Command` runs whatever `command` the Command Invocation names:
208+
209+```php
210+<?php // bin/cleanup.php
211+
212+use Symfony\Component\Console\Command\Command;
213+use Symfony\Component\Console\Input\InputInterface;
214+use Symfony\Component\Console\Output\OutputInterface;
215+
216+require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
217+
218+return static fn (): Command => (new Command('app:cleanup'))
219+ ->setCode(static function (InputInterface $input, OutputInterface $output): int {
220+ $output->writeln('Cleaned up');
221+
222+ return Command::SUCCESS;
223+ });
224+```
225+
226+This needs `symfony/console`, and `symfony/framework-bundle` for a `Symfony\Bundle\FrameworkBundle\Console\Application`.
227+
228+### Raw callable
229+
230+A closure returning another `Closure` talks to Scaleway without any translation.
231+The inner closure is built once per Warm Process and receives every Event and context as they are, CRON Invocations included:
232+
233+```php
234+<?php // public/raw.php
235+
236+return static fn (): Closure => static fn (array $event, mixed $context): array => [
237+ 'statusCode' => 200,
238+ 'headers' => ['Content-Type' => 'text/plain'],
239+ 'body' => 'Hello from '.($event['path'] ?? '/'),
240+];
241+```
242+
243+It must return a Function Response: an int `statusCode`, optional `headers` mapping names to a string or a list of strings, a string `body` and an optional bool `isBase64Encoded`.
244+Other keys are dropped, and any other return value fails the Invocation with a 500.
245+Command Invocations are not routed: the raw callable gets their Event like any other.
246+An invokable object is not taken for a raw callable; return `$object(...)` to make it one.
247+
248+## CRON triggers and Command Invocations
249+
250+### CRON triggers
24 251
25 A CRON trigger calls the Application with a `POST /` whose JSON body holds the trigger's arguments.252 A CRON trigger calls the Application with a `POST /` whose JSON body holds the trigger's arguments.
26-To run a console command instead, set a random `SCALEWAY_CRON_SECRET` as a secret environment variable of the function (for instance `openssl rand -hex 32`), and give the trigger these arguments:253+With a Kernel, handle it like any route:
254+
255+```php
256+#[Route('/', methods: ['POST'])]
257+public function cron(Request $request): Response
258+{
259+ $args = $request->toArray(); // the trigger's arguments
260+ // ...
261+}
262+```
263+
264+### Command Invocations
265+
266+A CRON trigger may run a console command instead, through the Console Application of the same Kernel.
267+
268+1. Generate a random secret, for instance with `openssl rand -hex 32`.
269+2. Set it as the `SCALEWAY_CRON_SECRET` secret environment variable of the function.
270+3. Give the CRON trigger these arguments:
27 271
28 ```json272 ```json
29 {"command": "app:sync", "args": {"source": "s3", "--force": true, "--tag": ["a", "b"]}, "secret": "<SCALEWAY_CRON_SECRET>"}273 {"command": "app:sync", "args": {"source": "s3", "--force": true, "--tag": ["a", "b"]}, "secret": "<SCALEWAY_CRON_SECRET>"}
30 ```274 ```
31 275
32-`args` maps argument names, and option names with their dashes, to values, as Symfony's `ArrayInput` does; the command runs without interaction, through the Console Application of the same Kernel.276+`args` is optional, and maps argument names, and option names with their dashes, to values, as Symfony's `ArrayInput` does.
33-Exit code 0 answers a 200 and any other exit code a 500, both with the command output as plain text body; a failure is also logged to stderr with that output.277+The command runs without interaction: questions get their default answer.
34-Without the variable, or with another secret, the body is a plain HTTP body and reaches `POST /`: an HTTP client cannot run commands without knowing the secret (see [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md)).278+Services are reset around each command, so it shares no state with the Invocations before and after it.
279+
280+| Outcome | Function Response |
281+| --- | --- |
282+| Exit code 0 | 200, the command output as plain text body |
283+| Any other exit code | 500, the command output as plain text body, also logged to stderr |
284+| `args` not a JSON object | 500 |
285+| The Front Controller returns a Response, a PSR-15 handler or a plain `HttpKernelInterface` | 500, as there is no Console Application to run the command |
286+
287+### Security model
288+
289+Nothing known in an Event tells a CRON Invocation from an HTTP one, so any internet client can send a body naming a command to a public function.
290+A body only becomes a Command Invocation when its `secret` matches `SCALEWAY_CRON_SECRET`, compared in constant time.
291+Otherwise the body reaches the Application as a plain HTTP body on `POST /`, and a body carrying a wrong `secret` is logged (without its value).
292+Without `SCALEWAY_CRON_SECRET`, or with an empty one, Command Invocations are off.
293+
294+Keep in mind that:
295+
296+- the secret is stored in clear in the trigger's arguments, readable by anyone who can read the function's triggers or the Terraform state;
297+- rotating it means updating the variable and every CRON trigger together.
298+
299+See [ADR 0005](docs/adr/0005-authenticate-command-invocations-with-a-shared-secret.md) for the alternatives considered.
300+
301+## Packaging
302+
303+```sh
304+vendor/bin/scaleway-package [function.zip]
305+```
306+
307+It builds the deployment zip in a private temporary directory, removed afterwards whatever happens:
308+
309+1. It copies the application, without the excluded files below and without the zip being written.
310+2. It runs `composer install --no-dev --classmap-authoritative` from the committed `composer.lock`, with `APP_ENV=prod` and `APP_DEBUG=0`.
311+ Relative `path` repositories are resolved against your application, and mirrored instead of symlinked.
312+3. It runs `bin/console cache:warmup`, when `bin/console` exists, to ship a warmed prod cache.
313+4. It zips the result, keeping the executable bits, and the `composer.lock` exactly as committed.
314+
315+It requires a committed `composer.lock`, for reproducible builds, and `handler.php`.
316+Symbolic links are followed: their target is copied.
317+
318+| Shipped | Not shipped |
319+| --- | --- |
320+| Your code, `composer.json`, `composer.lock`, `handler.php` | `vendor/` and `var/` from your machine (rebuilt) |
321+| `vendor/` without dev dependencies | `tests/`, `phpunit.xml(.dist)`, `.phpunit.cache`, `.phpunit.result.cache`, `.php-cs-fixer.cache` |
322+| `var/cache/prod`, warmed | `.env.local`, `.env.local.php`, `.env.*.local` |
323+| `.env`, `.env.prod`... as they are | `.git`, `.idea`, `.vscode`, `.DS_Store`, `node_modules` anywhere |
324+| | `.terraform`, `*.tfstate`, `*.tfstate.*` anywhere (Terraform state holds secrets in clear) |
325+
326+The full list is `Packager::EXCLUDES` in [src/Packager.php](src/Packager.php).
327+`--classmap-authoritative` means only classes known at build time can be autoloaded.
328+
329+Scaleway accepts zips up to 100 MiB, and up to 500 MiB of unzipped code ([limits](https://www.scaleway.com/en/docs/serverless-functions/reference-content/functions-limitations/)).
330+`scaleway-package` warns when the zip exceeds either, but still writes it.
331+
332+## Deployment
333+
334+[example/terraform](example/terraform/main.tf) deploys the [example application](example) with its `php85` runtime, `handler.handle`, `APP_ENV=prod`, the `APP_SECRET` and `SCALEWAY_CRON_SECRET` secrets, a CRON trigger calling `POST /` and one running a command.
335+Its [README](example/README.md#deploy-it) gives the commands.
336+That Terraform code was written against the `scaleway/scaleway` provider v2.92 documentation and has never been applied.
337+
338+Redeploy by running `scaleway-package` again, then `terraform apply`.
339+
340+## Local development with the Emulator
341+
342+```sh
343+vendor/bin/scaleway-serve [127.0.0.1:8000]
344+```
345+
346+The Emulator turns each HTTP request into an Event, calls your `handle()` and turns the Function Response back into the HTTP response.
347+`handle()` runs in one long-lived PHP process, as in a Warm Process: restart the Emulator after changing code.
348+A crashed process is replaced by a fresh one, as Scaleway starts a new instance.
349+
350+PHP's built-in server receives the requests, and forwards the Events to that process over a Unix socket in a private temporary directory.
351+The context passed to `handle()` is an empty array.
352+
353+The Event is built the way the platform is assumed to build it:
354+
355+- header names in `Title-Case`, repeated headers joined with `, `;
356+- the client address appended to `X-Forwarded-For`, and `X-Forwarded-Proto: http`;
357+- `queryStringParameters` as a map of strings, the last value of a repeated key winning;
358+- bodies that are not valid UTF-8 base64-encoded, with `isBase64Encoded: true`.
359+
360+Simulate a CRON trigger with a `POST /` carrying its arguments as JSON body:
361+
362+```sh
363+curl -X POST http://127.0.0.1:8000/ -H 'Content-Type: application/json' --data '{"job": "cleanup"}'
364+```
365+
366+Simulate a Command Invocation by starting the Emulator with `SCALEWAY_CRON_SECRET` set, and sending the [Command Invocation body](#command-invocations) the same way:
367+
368+```sh
369+SCALEWAY_CRON_SECRET=local-secret vendor/bin/scaleway-serve
370+curl -X POST http://127.0.0.1:8000/ --data '{"command": "app:greet", "args": {"name": "Scaleway"}, "secret": "local-secret"}'
371+```
372+
373+To run exactly what gets deployed, serve the packaged zip from a read-only copy:
374+
375+```sh
376+vendor/bin/scaleway-package
377+unzip -q function.zip -d /tmp/function && chmod -R a-w /tmp/function
378+APP_ENV=prod APP_SECRET=local php /tmp/function/vendor/bin/scaleway-serve
379+```
380+
381+## Warm Processes
382+
383+The Application is built once per Warm Process and reused by the following Invocations, like with FrankenPHP's worker mode or RoadRunner ([ADR 0002](docs/adr/0002-reuse-application-across-invocations.md)).
384+If Scaleway does not keep processes warm, this degrades to one boot per Invocation.
385+
386+Between Invocations, for a Kernel:
387+
388+- `terminate()` runs after each Invocation, and a failure in it is logged without changing the Function Response;
389+- the `services_resetter` resets the services tagged `kernel.reset` before the next request, as Symfony's Kernel does;
390+- uploaded files are deleted, and output buffers the Application left open are closed.
391+
392+Everything else survives, so your application must be safe for long-running execution:
393+
394+- do not keep per-request state in static properties or in services that do not implement `ResetInterface`;
395+- in-memory caches and collections grow across Invocations unless reset;
396+- connections (database, HTTP clients) may have been closed by the server while the process was idle;
397+- `exit()` or a fatal error ends the process, and the next Invocation pays a cold start.
398+
399+## Limitations and platform caveats
400+
401+### Requests and responses
402+
403+- **Superglobals**: `$_GET`, `$_POST`, `$_COOKIE`, `$_FILES` and the request entries of `$_SERVER` (`REQUEST_URI`, `HTTP_*`...) are not populated per Invocation.
404+ Read the `Request` object instead; `Request::createFromGlobals()` does not describe the Invocation.
405+- **Output**: only the returned `Response` reaches the client.
406+ `echo` outside the Response, `header()` and `http_response_code()` do not.
407+- **Query strings**: the Event carries `queryStringParameters` as a map, so a repeated key such as `a=1&a=2`, or `tags[]=a&tags[]=b`, likely reaches the Application with one value only.
408+ Keys are then parsed like PHP does, so `a.b` becomes `a_b` and `a[b]` nests.
409+- **Form bodies**: `application/x-www-form-urlencoded` bodies are parsed for `POST`, `PUT`, `DELETE`, `PATCH` and `QUERY`, `multipart/form-data` only for `POST`, as PHP does.
410+ Uploaded files are `UploadedFile` objects in test mode: `move()` works, `is_uploaded_file()` does not.
411+- **Cookies**: request cookie names are taken verbatim: unlike PHP's `$_COOKIE`, dots and spaces are not turned into underscores and `a[b]` does not nest.
412+- **Streaming**: `StreamedResponse` and `BinaryFileResponse` are buffered into one Function Response; Server-Sent Events and long downloads are not possible.
413+ Bodies that are not valid UTF-8 are sent base64-encoded.
414+- **PSR-15 responses** go through Symfony's `Response`, which adds `Cache-Control: no-cache, private` and `Date` when they are missing.
415+- **HEAD requests**: only FrameworkBundle's `ResponseListener` strips the body of a `HEAD` response.
416+ A bare `HttpKernelInterface`, a Response Front Controller or a PSR-15 handler returns the full body, unless it handles `HEAD` itself.
417+- **Request size**: Scaleway documents a 6 MiB limit for request bodies.
418+
419+### Client IP and trusted proxies
420+
421+The `Request` always sees `127.0.0.1` as its peer, standing for the platform proxy, which the runtime trusts for `X-Forwarded-For`, `-Host`, `-Port` and `-Proto`.
422+If your application configures its own trusted proxies (`framework.trusted_proxies`), the runtime leaves them alone: include `127.0.0.1`, or `getClientIp()`, `getHost()` and `isSecure()` will ignore the platform's headers.
423+
424+> [!CAUTION]
425+> Whether Scaleway overwrites, appends to or passes through the `X-Forwarded-*` headers a client sends is not verified yet.
426+> If it passes them through, a client can choose the IP returned by `getClientIp()` and the host used to generate absolute URLs.
427+> Do not rely on them for access control or rate limiting until the probe settles it.
428+
429+### Composer at deploy time
430+
431+Scaleway documents that it installs the dependencies of a shipped `composer.json` at deploy time.
432+Whether it does so over the shipped `vendor/` is not verified: if it does, a `composer.lock` installing packages from a `path` repository outside the zip, as the example's does, likely fails the deployment.
433+
434+### Windows
435+
436+`scaleway-serve` and `scaleway-package` rely on Unix sockets and `/dev/null`: they run on macOS and Linux, not on Windows outside WSL.
437+Without the `pcntl` extension, stopping the Emulator with `kill` may leave its PHP processes running.
438+
439+### Unverified platform facts
440+
441+The runtime and the Emulator rely on these, still unmeasured on Scaleway.
442+The [probe function](probe) measures each of them; until its results are folded into this README, treat them as assumptions.
443+
444+- The CRON Event shape: a `POST /` whose body is the trigger's arguments as JSON, and whether it carries a marker HTTP clients cannot forge.
445+- That processes are kept warm between Invocations.
446+- How `X-Forwarded-*` headers sent by clients are handled.
447+- How repeated query keys are folded, and the case of header names.
448+- That multi-value response headers (lists, as for several `Set-Cookie`) are sent as repeated headers.
449+- When request bodies are base64-encoded, and the actual body size limit.
450+- The Content-Type added to responses without one, and how binary responses are served.
451+- The type and content of `$context`.
452+- That plain and secret environment variables reach `$_SERVER`, where `APP_RUNTIME_OPTIONS`, `APP_ENV` and `APP_DEBUG` are read.
453+- That the code directory is read-only and `/tmp` writable.
454+- Whether Composer runs over the shipped `vendor/` at deploy time.
455+- Where stdout, stderr and uncaught exceptions go.
456+
457+## Contributing
458+
459+```sh
460+composer install
461+composer check # PHP-CS-Fixer (dry run), PHPStan (max level) and PHPUnit
462+composer cs-fix # applies the coding style
463+```
464+
465+CI runs `composer validate --strict` and `composer check` on PHP 8.4 and 8.5, each against Symfony 7.4 and 8.x, the whole Symfony stack being pinned through Flex's `SYMFONY_REQUIRE`.
466+It also packages the [example application](example), serves its zip read-only in prod through the Emulator, and runs its [end-to-end scenarios](example/e2e/run.sh).
467+
468+The repository holds:
35 469
36-A Front Controller may also return a Console `Application` or a `Command`, as with SymfonyRuntime: the function then only runs Command Invocations, and answers any other Invocation with a 403.470+- `src/`, `bin/`, `resources/`: the package;
37-A single `Command` runs whatever `command` the arguments name.471+- `tests/`: PHPUnit tests, packaging included (it runs Composer, offline);
38-Running commands needs `symfony/console`, and `symfony/framework-bundle` for a Kernel.472+- `example/`: a demo Symfony application consuming the package through a `path` repository, with Terraform code to deploy it;
473+- `probe/`: a dependency-free function measuring the open platform facts;
474+- `docs/`: the [implementation plan](docs/plan.md) and the [ADRs](docs/adr).
39 475
40 ## License476 ## License
41 477