Skip to content

Commit d52ce94

Browse files
committed
docs: improve Mercure documentation and various other parts
1 parent b749f52 commit d52ce94

File tree

8 files changed

+243
-47
lines changed

8 files changed

+243
-47
lines changed

.gitleaksignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/github/workspace/docs/mercure.md:jwt:65

caddy/extinit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func init() {
1717
caddycmd.RegisterCommand(caddycmd.Command{
1818
Name: "extension-init",
1919
Usage: "go_extension.go [--verbose]",
20-
Short: "(Experimental) Initializes a PHP extension from a Go file",
20+
Short: "Initializes a PHP extension from a Go file (EXPERIMENTAL)",
2121
Long: `
2222
Initializes a PHP extension from a Go file. This command generates the necessary C files for the extension, including the header and source files, as well as the arginfo file.`,
2323
CobraFunc: func(cmd *cobra.Command) {

docs/config.md

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
# Configuration
22

3-
FrankenPHP, Caddy as well as the Mercure and Vulcain modules can be configured using [the formats supported by Caddy](https://caddyserver.com/docs/getting-started#your-first-config).
3+
FrankenPHP, Caddy as well as the [Mercure](mercure.md) and [Vulcain](https://vulcain.rocks) modules can be configured using [the formats supported by Caddy](https://caddyserver.com/docs/getting-started#your-first-config).
44

5-
In [the Docker images](docker.md), the `Caddyfile` is located at `/etc/frankenphp/Caddyfile`.
6-
The static binary will also look for the `Caddyfile` in the directory where the `frankenphp run` command is executed.
5+
The most common format is the `Caddyfile`, which is a simple, human-readable text format.
6+
By default, FrankenPHP will look for a `Caddyfile` in the current directory.
77
You can specify a custom path with the `-c` or `--config` option.
88

9+
A minimal `Caddyfile` to serve a PHP application is shown below:
10+
11+
```caddyfile
12+
# The hostname to respond to
13+
localhost
14+
15+
# Optionaly, the directory to serve files from, otherwise defaults to the current directory
16+
#root public/
17+
php_server
18+
```
19+
20+
A more advanced `Caddyfile` enabling more features and providing convenient environment variables is provided [in the FrankenPHP repository](https://github.com/php/frankenphp/blob/main/caddy/frankenphp/Caddyfile),
21+
and with Docker images.
22+
923
PHP itself can be configured [using a `php.ini` file](https://www.php.net/manual/en/configuration.file.php).
1024

11-
Depending on your installation method, the PHP interpreter will look for configuration files in locations described below.
25+
Depending on your installation method, FrankenPHP and the PHP interpreter will look for configuration files in locations described below.
1226

1327
## Docker
1428

29+
FrankenPHP:
30+
31+
- `/etc/frankenphp/Caddyfile`: the main configuration file
32+
- `/etc/frankenphp/caddy.d/*.caddy`: additional configuration files that are loaded automatically
33+
34+
PHP:
35+
1536
- `php.ini`: `/usr/local/etc/php/php.ini` (no `php.ini` is provided by default)
1637
- additional configuration files: `/usr/local/etc/php/conf.d/*.ini`
1738
- PHP extensions: `/usr/local/lib/php/extensions/no-debug-zts-<YYYYMMDD>/`
@@ -29,12 +50,25 @@ RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
2950

3051
## RPM and Debian packages
3152

53+
FrankenPHP:
54+
55+
- `/etc/frankenphp/Caddyfile`: the main configuration file
56+
- `/etc/frankenphp/caddy.d/*.caddy`: additional configuration files that are loaded automatically
57+
58+
PHP:
59+
3260
- `php.ini`: `/etc/frankenphp/php.ini` (a `php.ini` file with production presets is provided by default)
3361
- additional configuration files: `/etc/frankenphp/php.d/*.ini`
3462
- PHP extensions: `/usr/lib/frankenphp/modules/`
3563

3664
## Static binary
3765

66+
FrankenPHP:
67+
68+
- In the current working directory: `Caddyfile`
69+
70+
PHP:
71+
3872
- `php.ini`: The directory in which `frankenphp run` or `frankenphp php-server` is executed, then `/etc/frankenphp/php.ini`
3973
- additional configuration files: `/etc/frankenphp/php.d/*.ini`
4074
- PHP extensions: cannot be loaded, bundle them in the binary itself
@@ -229,34 +263,6 @@ and otherwise forward the request to the worker matching the path pattern.
229263
}
230264
```
231265

232-
### Full Duplex (HTTP/1)
233-
234-
When using HTTP/1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body
235-
has been read. (for example: WebSocket, Server-Sent Events, etc.)
236-
237-
This is an opt-in configuration that needs to be added to the global options in the `Caddyfile`:
238-
239-
```caddyfile
240-
{
241-
servers {
242-
enable_full_duplex
243-
}
244-
}
245-
```
246-
247-
> [!CAUTION]
248-
>
249-
> Enabling this option may cause old HTTP/1.x clients that don't support full-duplex to deadlock.
250-
> This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config:
251-
252-
```sh
253-
CADDY_GLOBAL_OPTIONS="servers {
254-
enable_full_duplex
255-
}"
256-
```
257-
258-
You can find more information about this setting in the [Caddy documentation](https://caddyserver.com/docs/caddyfile/options#enable-full-duplex).
259-
260266
## Environment Variables
261267

262268
The following environment variables can be used to inject Caddy directives in the `Caddyfile` without modifying it:
@@ -293,6 +299,43 @@ You can also change the PHP configuration using the `php_ini` directive in the `
293299
}
294300
```
295301

302+
### Disabling HTTPS
303+
304+
By default, FrankenPHP will automatically enable HTTPS using for all the hostnames, including `localhost`.
305+
If you want to disable HTTPS (for example in a development environment), you can set the `SERVER_NAME` environment variable to `http://` or `:80`:
306+
307+
Alternatively, you can use all other methods described in the [Caddy documentation](https://caddyserver.com/docs/automatic-https#activation).
308+
309+
If you want to use HTTPS with the `127.0.0.1` IP address instead of the `localhost` hostname, please read the [known issues](known-issues.md#using-https127001-with-docker) section.
310+
311+
### Full Duplex (HTTP/1)
312+
313+
When using HTTP/1.x, it may be desirable to enable full-duplex mode to allow writing a response before the entire body
314+
has been read. (for example: [Mercure](mercure.md), WebSocket, Server-Sent Events, etc.)
315+
316+
This is an opt-in configuration that needs to be added to the global options in the `Caddyfile`:
317+
318+
```caddyfile
319+
{
320+
servers {
321+
enable_full_duplex
322+
}
323+
}
324+
```
325+
326+
> [!CAUTION]
327+
>
328+
> Enabling this option may cause old HTTP/1.x clients that don't support full-duplex to deadlock.
329+
> This can also be configured using the `CADDY_GLOBAL_OPTIONS` environment config:
330+
331+
```sh
332+
CADDY_GLOBAL_OPTIONS="servers {
333+
enable_full_duplex
334+
}"
335+
```
336+
337+
You can find more information about this setting in the [Caddy documentation](https://caddyserver.com/docs/caddyfile/options#enable-full-duplex).
338+
296339
## Enable the Debug Mode
297340

298341
When using the Docker image, set the `CADDY_GLOBAL_OPTIONS` environment variable to `debug` to enable the debug mode:

docs/docker.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Building Custom Docker Image
22

3-
[FrankenPHP Docker images](https://hub.docker.com/r/dunglas/frankenphp) are based on [official PHP images](https://hub.docker.com/_/php/). Debian and Alpine Linux variants are provided for popular architectures. Debian variants are recommended.
3+
[FrankenPHP Docker images](https://hub.docker.com/r/dunglas/frankenphp) are based on [official PHP images](https://hub.docker.com/_/php/).
4+
Debian and Alpine Linux variants are provided for popular architectures.
5+
Debian variants are recommended.
46

57
Variants for PHP 8.2, 8.3 and 8.4 are provided.
68

@@ -28,6 +30,11 @@ docker build -t my-php-app .
2830
docker run -it --rm --name my-running-app my-php-app
2931
```
3032

33+
## How to Tweak the Configuration
34+
35+
For convenience, [a default `Caddyfile`](https://github.com/php/frankenphp/blob/main/caddy/frankenphp/Caddyfile) containing
36+
useful environment variables is provided in the image.
37+
3138
## How to Install More PHP Extensions
3239

3340
The [`docker-php-extension-installer`](https://github.com/mlocati/docker-php-extension-installer) script is provided in the base image.

docs/extensions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ As covered in the manual implementation section below as well, you need to [get
3333
The first step to writing a PHP extension in Go is to create a new Go module. You can use the following command for this:
3434

3535
```console
36-
go mod init example.com/example
36+
go mod init example.com/example
3737
```
3838

3939
The second step is to [get the PHP sources](https://www.php.net/downloads.php) for the next steps. Once you have them, decompress them into the directory of your choice, not inside your Go module:
@@ -49,7 +49,7 @@ Everything is now setup to write your native function in Go. Create a new file n
4949
```go
5050
package example
5151

52-
// #include <Zend/zend_types.h>
52+
// #include <Zend/zend_types.h>
5353
import "C"
5454
import (
5555
"strings"
@@ -126,7 +126,7 @@ package example
126126
import "C"
127127
import (
128128
"unsafe"
129-
129+
130130
"github.com/dunglas/frankenphp"
131131
)
132132

@@ -790,7 +790,7 @@ import "C"
790790
import (
791791
"unsafe"
792792
"strings"
793-
793+
794794
"github.com/dunglas/frankenphp"
795795
)
796796

docs/known-issues.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ The following extensions are known not to be compatible with FrankenPHP:
1313

1414
The following extensions have known bugs and unexpected behaviors when used with FrankenPHP:
1515

16-
| Name | Problem |
17-
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18-
| [ext-openssl](https://www.php.net/manual/en/book.openssl.php) | When using a static build of FrankenPHP (built with the musl libc), the OpenSSL extension may crash under heavy loads. A workaround is to use a dynamically linked build (like the one used in Docker images). This bug is [being tracked by PHP](https://github.com/php/php-src/issues/13648). |
16+
| Name | Problem |
17+
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| [ext-openssl](https://www.php.net/manual/en/book.openssl.php) | When using musl libc, the OpenSSL extension may crash under heavy loads. The problem doesn't occur when using the more popular GNU libc. This bug is [being tracked by PHP](https://github.com/php/php-src/issues/13648). |
1919

2020
## get_browser
2121

2222
The [get_browser()](https://www.php.net/manual/en/function.get-browser.php) function seems to perform badly after a while. A workaround is to cache (e.g. with [APCu](https://www.php.net/manual/en/book.apcu.php)) the results per User Agent, as they are static.
2323

2424
## Standalone Binary and Alpine-based Docker Images
2525

26-
The standalone binary and Alpine-based Docker images (`dunglas/frankenphp:*-alpine`) use [musl libc](https://musl.libc.org/) instead of [glibc and friends](https://www.etalabs.net/compare_libcs.html), to keep a smaller binary size. This may lead to some compatibility issues. In particular, the glob flag `GLOB_BRACE` is [not available](https://www.php.net/manual/en/function.glob.php)
26+
The fully binary and Alpine-based Docker images (`dunglas/frankenphp:*-alpine`) use [musl libc](https://musl.libc.org/) instead of [glibc and friends](https://www.etalabs.net/compare_libcs.html), to keep a smaller binary size.
27+
This may lead to some compatibility issues.
28+
In particular, the glob flag `GLOB_BRACE` is [not available](https://www.php.net/manual/en/function.glob.php)
29+
30+
Prefer using the GNU variant of the static binary and Debian-based Docker images if you encounter issues.
2731

2832
## Using `https://127.0.0.1` with Docker
2933

docs/laravel.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ The `octane:frankenphp` command can take the following options:
7676
> [!TIP]
7777
> To get structured JSON logs (useful when using log analytics solutions), explicitly the pass `--log-level` option.
7878
79+
See also [how to use Mercure with Octane](#mercure-support).
80+
7981
Learn more about [Laravel Octane in its official documentation](https://laravel.com/docs/octane).
8082

8183
## Laravel Apps As Standalone Binaries
@@ -166,6 +168,34 @@ This is not suitable for embedded applications, as each new version will be extr
166168

167169
Set the `LARAVEL_STORAGE_PATH` environment variable (for example, in your `.env` file) or call the `Illuminate\Foundation\Application::useStoragePath()` method to use a directory outside the temporary directory.
168170

171+
### Mercure Support
172+
173+
[Mercure](https://mercure.rocks) is a great way to add real-time capabilities to your Laravel apps.
174+
FrankenPHP includes [Mercure support out of the box](mercure.md).
175+
176+
If you are not using [Octane](#laravel-octane), see [the Mercure documentation entry](mercure.md).
177+
178+
If you are using Octane, you can use enable Mercure support by adding the following lines to your `config/octane.php` file:
179+
180+
```php
181+
// ...
182+
183+
return [
184+
// ...
185+
186+
'mercure' => [
187+
'anonymous' => true,
188+
'publisher_jwt' => '!ChangeThisMercureHubJWTSecretKey!',
189+
'subscriber_jwt' => '!ChangeThisMercureHubJWTSecretKey!',
190+
],
191+
];
192+
```
193+
194+
You can use [all directives supported by Mercure](https://mercure.rocks/docs/hub/config#directives) in this array.
195+
196+
To publish and subscribe to updates, we recommend using the [Laravel Mercure Broadcaster](https://github.com/mvanduijker/laravel-mercure-broadcaster) library.
197+
Alternatively, see [the Mercure documentation](mercure.md) to do it in pure PHP and JavaScript.
198+
169199
### Running Octane With Standalone Binaries
170200

171201
It's even possible to package Laravel Octane apps as standalone binaries!

0 commit comments

Comments
 (0)