Skip to content

Commit

Permalink
Merge branch 'main' into feat/auto-scale-clock-time
Browse files Browse the repository at this point in the history
# Conflicts:
#	thread-worker.go
#	watcher_test.go
  • Loading branch information
Alliballibaba2 committed Jan 22, 2025
2 parents 1d899db + eee1de1 commit 9a83ab1
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 97 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:
IMAGE_NAME: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/')) && 'dunglas/frankenphp' || 'dunglas/frankenphp-dev' }}
jobs:
prepare:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
# Push if it's a scheduled job, a tag, or if we're committing to the main branch
push: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) && true || false }}
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || steps.check.outputs.ref || 'dev' }}
PHP_VERSION: ${{ steps.check.outputs.php_version }}
build:
runs-on: ubuntu-latest
runs-on: ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
needs:
- prepare
if: ${{ !fromJson(needs.prepare.outputs.skip) }}
Expand All @@ -111,12 +111,8 @@ jobs:
platform: ${{ fromJson(needs.prepare.outputs.platforms) }}
include:
- race: ""
qemu: true
- platform: linux/amd64
qemu: false
race: "-race" # The Go race detector is only supported on amd64
- platform: linux/386
qemu: false
exclude:
# arm/v6 is only available for Alpine: https://github.com/docker-library/golang/issues/502
- variant: php-${{ needs.prepare.outputs.php82_version }}-bookworm
Expand All @@ -132,11 +128,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.ref }}
- name: Set up QEMU
if: matrix.qemu
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
Expand Down Expand Up @@ -202,7 +193,7 @@ jobs:
if-no-files-found: error
retention-days: 1
- name: Run tests
if: ${{ !matrix.qemu && !fromJson(needs.prepare.outputs.push) }}
if: ${{ !fromJson(needs.prepare.outputs.push) }}
run: |
docker run --platform=${{ matrix.platform }} --rm \
"$(jq -r '."builder-${{ matrix.variant }}"."containerimage.config.digest"' <<< "${METADATA}")" \
Expand All @@ -211,7 +202,7 @@ jobs:
METADATA: ${{ steps.build.outputs.metadata }}
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
push:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs:
- prepare
- build
Expand Down
15 changes: 3 additions & 12 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ env:
IMAGE_NAME: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/')) && 'dunglas/frankenphp' || 'dunglas/frankenphp-dev' }}
jobs:
prepare:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
push: ${{ toJson((steps.check.outputs.ref || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) && true || false) }}
platforms: ${{ steps.matrix.outputs.platforms }}
Expand Down Expand Up @@ -74,17 +74,13 @@ jobs:
debug: [false]
mimalloc: [false]
include:
- qemu: true
- platform: linux/amd64
qemu: false
- platform: linux/amd64
qemu: false
debug: true
- platform: linux/amd64
qemu: false
mimalloc: true
name: Build ${{ matrix.platform }} static binary${{ matrix.debug && ' (debug)' || '' }}${{ matrix.mimalloc && ' (mimalloc)' || '' }}
runs-on: ubuntu-latest
runs-on: ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
needs: [prepare]
steps:
- name: Prepare
Expand All @@ -95,11 +91,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.ref }}
- name: Set up QEMU
if: matrix.qemu
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
Expand Down Expand Up @@ -187,7 +178,7 @@ jobs:

# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
push:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs:
- prepare
- build-linux
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ frankenphp php-cli /path/to/your/script.php

## Docs

* [The worker mode](https://frankenphp.dev/docs/worker/)
* [Classic mode](https://frankenphp.dev/docs/classic/)
* [Worker mode](https://frankenphp.dev/docs/worker/)
* [Early Hints support (103 HTTP status code)](https://frankenphp.dev/docs/early-hints/)
* [Real-time](https://frankenphp.dev/docs/mercure/)
* [Configuration](https://frankenphp.dev/docs/config/)
Expand All @@ -86,3 +87,4 @@ frankenphp php-cli /path/to/your/script.php
* [Drupal](https://github.com/dunglas/frankenphp-drupal)
* [Joomla](https://github.com/alexandreelise/frankenphp-joomla)
* [TYPO3](https://github.com/ochorocho/franken-typo3)
* [Magento2](https://github.com/ekino/frankenphp-magento2)
15 changes: 0 additions & 15 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ RUN apk add --no-cache --virtual .build-deps \
sqlite-dev \
upx

# FIXME: temporary workaround for https://github.com/golang/go/issues/68285
WORKDIR /
RUN git clone https://go.googlesource.com/go goroot
WORKDIR /goroot
# Revert https://github.com/golang/go/commit/3560cf0afb3c29300a6c88ccd98256949ca7a6f6 to prevent the crash with musl
RUN git config --global user.email "[email protected]" && \
git config --global user.name "Build" && \
git checkout "$(go env GOVERSION)" && \
git revert 3560cf0afb3c29300a6c88ccd98256949ca7a6f6
WORKDIR /goroot/src
ENV GOHOSTARCH="$TARGETARCH"
RUN ./make.bash
ENV PATH="/goroot/bin:$PATH"
RUN go version

WORKDIR /go/src/app

COPY --link go.mod go.sum ./
Expand Down
2 changes: 1 addition & 1 deletion caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func TestAllDefinedServerVars(t *testing.T) {
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: 14", // maliciously set to 14
"Special-Chars: <%00>",
"Host: Malicous Host",
"Host: Malicious Host",
"X-Empty-Header:",
},
bytes.NewBufferString("foo=bar"),
Expand Down
10 changes: 5 additions & 5 deletions caddy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/caddyserver/caddy/v2 v2.9.1
github.com/caddyserver/certmagic v0.21.6
github.com/dunglas/caddy-cbrotli v1.0.0
github.com/dunglas/frankenphp v1.3.6
github.com/dunglas/mercure/caddy v0.18.0
github.com/dunglas/vulcain/caddy v1.1.0
github.com/dunglas/frankenphp v1.4.1
github.com/dunglas/mercure/caddy v0.18.1
github.com/dunglas/vulcain/caddy v1.1.1
github.com/prometheus/client_golang v1.20.5
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -55,8 +55,8 @@ require (
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/dunglas/httpsfv v1.0.2 // indirect
github.com/dunglas/mercure v0.18.0 // indirect
github.com/dunglas/vulcain v1.1.0 // indirect
github.com/dunglas/mercure v0.18.1 // indirect
github.com/dunglas/vulcain v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
Expand Down
16 changes: 8 additions & 8 deletions caddy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ github.com/dunglas/caddy-cbrotli v1.0.0 h1:+WNqXBkWyMcIpXB2rVZ3nwcElUbuAzf0kPxNX
github.com/dunglas/caddy-cbrotli v1.0.0/go.mod h1:KZsUu3fnQBgO0o3YDoQuO3Z61dFgUncr1F8rg8acwQw=
github.com/dunglas/httpsfv v1.0.2 h1:iERDp/YAfnojSDJ7PW3dj1AReJz4MrwbECSSE59JWL0=
github.com/dunglas/httpsfv v1.0.2/go.mod h1:zID2mqw9mFsnt7YC3vYQ9/cjq30q41W+1AnDwH8TiMg=
github.com/dunglas/mercure v0.18.0 h1:REdWvU3DMpnYW43s4S3mTSnujMWGjClG8umkVw8mcfU=
github.com/dunglas/mercure v0.18.0/go.mod h1:Fgquo4PTXop+TtpkXiE4CyV2i5+FmD/dCKVJ6fsOBEc=
github.com/dunglas/mercure/caddy v0.18.0 h1:Akns0zO2CUKQHkT5oiMdLHRKWaOZibON9iuH5aiBYds=
github.com/dunglas/mercure/caddy v0.18.0/go.mod h1:rmgtvcWws2K8pdhbpCE3mcUTkGeaRq9rRteS5coB9g8=
github.com/dunglas/vulcain v1.1.0 h1:HKA5hmubA8VYlmArHEo8IpCfFQRm627rHn8GaxkK3nI=
github.com/dunglas/vulcain v1.1.0/go.mod h1:5YslB+KQI6SbghCDB3zrDyGtS2WCLvu+oFBkHi6mo+w=
github.com/dunglas/vulcain/caddy v1.1.0 h1:O/65ccL4peT31+dmRzK73xl4RtqdZKPDIiXxWNoeA40=
github.com/dunglas/vulcain/caddy v1.1.0/go.mod h1:hQOmuJPE29xGSd/ILcoT0tybK1CcATXUOdQOMGr/FEQ=
github.com/dunglas/mercure v0.18.1 h1:cpY6p5IIonjdUl8RXuIfNP41mR6GBE4RNusKiJWM+FQ=
github.com/dunglas/mercure v0.18.1/go.mod h1:Fgquo4PTXop+TtpkXiE4CyV2i5+FmD/dCKVJ6fsOBEc=
github.com/dunglas/mercure/caddy v0.18.1 h1:hUXG1HjLBqnePVZDH9pu7DODOuUK2nK/7xPAK4/c03U=
github.com/dunglas/mercure/caddy v0.18.1/go.mod h1:tydZIo08KxuTbUoW8AwwER/kLYXYjKlpfR9QuvdABWU=
github.com/dunglas/vulcain v1.1.1 h1:nWh6sEhaeSla3IVXpzxQ8tK1nEr4lM1Q/HW8EVdpIgU=
github.com/dunglas/vulcain v1.1.1/go.mod h1:5YslB+KQI6SbghCDB3zrDyGtS2WCLvu+oFBkHi6mo+w=
github.com/dunglas/vulcain/caddy v1.1.1 h1:TT90lkiqnF1rGEyWXwZwhnuTRInNmYgJsFzR9ZH8pbQ=
github.com/dunglas/vulcain/caddy v1.1.1/go.mod h1:6aXBrXh46qlJv9rIBlX5DlxzmRPJyVWpnFp8JMkpBNI=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
Expand Down
9 changes: 9 additions & 0 deletions docs/classic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Using Classic Mode

Without any additional configuration, FrankenPHP operates in classic mode. In this mode, FrankenPHP functions like a traditional PHP server, directly serving PHP files. This makes it a seamless drop-in replacement for PHP-FPM or Apache with mod_php.

Similar to Caddy, FrankenPHP accepts an unlimited number of connections and uses a [fixed number of threads](config.md#caddyfile-config) to serve them. The number of accepted and queued connections is limited only by the available system resources. The PHP thread pool operates with a fixed number of threads initialized at startup, comparable to the static mode of PHP-FPM.

Queued connections will wait indefinitely until a PHP thread is available to serve them. To prevent that, set a reasonable [write timeout in Caddy](https://caddyserver.com/docs/caddyfile/options#timeouts).

Each Caddy instance will only spin up one FrankenPHP thread pool, which will be shared across all `php_server` blocks.
1 change: 1 addition & 0 deletions docs/cn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ docker run -v $PWD:/app/public \
* [Drupal](https://github.com/dunglas/frankenphp-drupal)
* [Joomla](https://github.com/alexandreelise/frankenphp-joomla)
* [TYPO3](https://github.com/ochorocho/franken-typo3)
* [Magento2](https://github.com/ekino/frankenphp-magento2)
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FROM dunglas/frankenphp
# Production:
RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini

# Or developement:
# Or development:
RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
```

Expand Down
1 change: 1 addition & 0 deletions docs/fr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ frankenphp php-cli /path/to/your/script.php
* [Drupal](https://github.com/dunglas/frankenphp-drupal)
* [Joomla](https://github.com/alexandreelise/frankenphp-joomla)
* [TYPO3](https://github.com/ochorocho/franken-typo3)
* [Magento2](https://github.com/ekino/frankenphp-magento2)
2 changes: 1 addition & 1 deletion docs/fr/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Le binaire autonome et les images docker basées sur Alpine (`dunglas/frankenphp
## Utilisation de `https://127.0.0.1` avec Docker

Par défaut, FrankenPHP génère un certificat TLS pour `localhost`.
C'est l'option est la plus simple et est recommandée pour le développement local.
C'est l'option la plus simple et recommandée pour le développement local.

Si vous voulez vraiment utiliser `127.0.0.1` comme hôte, il est possible de configure FrankenPHP pour générer un certificat pour cela en définissant le nom du serveur à `127.0.0.1`.

Expand Down
4 changes: 3 additions & 1 deletion docs/laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Alternatively, you can run your Laravel projects with FrankenPHP from your local
# Enable compression (optional)
encode zstd br gzip
# Execute PHP files from the public/ directory and serve assets
php_server
php_server {
try_files {path} index.php
}
}
```
Expand Down
40 changes: 39 additions & 1 deletion docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ However, it is possible to substantially improve performance using an appropriat
By default, FrankenPHP starts 2 times more threads and workers (in worker mode) than the available numbers of CPU.

The appropriate values depend heavily on how your application is written, what it does and your hardware.
We strongly recommend changing these values.
We strongly recommend changing these values. For best system stability, it is recommended to have `num_threads` x `memory_limit` < `available_memory`.

To find the right values, it's best to run load tests simulating real traffic.
[k6](https://k6.io) and [Gatling](https://gatling.io) are good tools for this.
Expand Down Expand Up @@ -75,6 +75,44 @@ php_server {
}
```

## `try_files`

Besides static files and PHP files, `php_server` will also try to serve your application's index
and directory index files (`/path/` -> `/path/index.php`). If you don't need directory indices,
you can disable them by explicitly defining `try_files` like this:

```caddyfile
php_server {
try_files {path} index.php
root /root/to/your/app # explicitly adding the root here allows for better caching
}
```

This can significantly reduce the number of unnecessary file operations.

An alternate approach with 0 unnecessary file system operations would be to instead use the `php` directive and split
files from PHP by path. This approach works well if your entire application is served by one entry file.
An example [configuration](config.md#caddyfile-config) that serves static files behind an `/assets` folder could look like this:

```caddyfile
route {
@assets {
path /assets/*
}
# everything behind /assets is handled by the file server
file_server @assets {
root /root/to/your/app
}
# everything that is not in /assets is handled by your index or worker PHP file
rewrite index.php
php {
root /root/to/your/app # explicitly adding the root here allows for better caching
}
}
```

## Placeholders

You can use [placeholders](https://caddyserver.com/docs/conventions#placeholders) in the `root` and `env` directives.
Expand Down
2 changes: 1 addition & 1 deletion docs/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Refer to "[Building Custom Docker Image](docker.md)" for more details and option
and to learn how to customize the configuration, install PHP extensions and Caddy modules.

If your project uses Composer,
be sure to include it in the Docker image and to install your depedencies.
be sure to include it in the Docker image and to install your dependencies.

Then, add a `compose.yaml` file:

Expand Down
1 change: 1 addition & 0 deletions docs/tr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ Ayrıca aşağıdaki tek komut satırı ile de çalıştırabilirsiniz:
* [Drupal](https://github.com/dunglas/frankenphp-drupal)
* [Joomla](https://github.com/alexandreelise/frankenphp-joomla)
* [TYPO3](https://github.com/ochorocho/franken-typo3)
* [Magento2](https://github.com/ekino/frankenphp-magento2)
9 changes: 3 additions & 6 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ static void frankenphp_worker_request_shutdown() {
zend_end_try();

zend_set_memory_limit(PG(memory_limit));
/* TODO: remove next line when https://github.com/php/php-src/pull/14499 will
* be available */
SG(rfc1867_uploaded_files) = NULL;
}

PHPAPI void get_full_env(zval *track_vars_array) {
Expand Down Expand Up @@ -434,8 +431,8 @@ PHP_FUNCTION(frankenphp_handle_request) {
}

/*
* If an exception occured, print the message to the client before closing the
* connection
* If an exception occurred, print the message to the client before
* closing the connection
*/
if (EG(exception)) {
zend_exception_error(EG(exception), E_ERROR);
Expand Down Expand Up @@ -927,7 +924,7 @@ static void *php_main(void *arg) {
#else
php_tsrm_startup();
#endif
/*tsrm_error_set(TSRM_ERROR_LEVEL_INFO, NULL);*/
/*tsrm_error_set(TSRM_ERROR_LEVEL_INFO, NULL);*/
#ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
#endif
Expand Down
14 changes: 7 additions & 7 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// In all tests, headers added to requests are copied on the heap using strings.Clone.
// This was originally a workaround for https://github.com/golang/go/issues/65286#issuecomment-1920087884 (fixed in Go 1.22),
// but this allows to catch panics occuring in real life but not when the string is in the internal binary memory.
// but this allows to catch panics occurring in real life but not when the string is in the internal binary memory.

package frankenphp_test

Expand Down Expand Up @@ -41,7 +41,7 @@ type testOptions struct {
watch []string
nbWorkers int
env map[string]string
nbParrallelRequests int
nbParallelRequests int
realServer bool
logger *zap.Logger
initOpts []frankenphp.Option
Expand All @@ -51,8 +51,8 @@ func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *
if opts == nil {
opts = &testOptions{}
}
if opts.nbParrallelRequests == 0 {
opts.nbParrallelRequests = 100
if opts.nbParallelRequests == 0 {
opts.nbParallelRequests = 100
}

cwd, _ := os.Getwd()
Expand Down Expand Up @@ -87,8 +87,8 @@ func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *
}

var wg sync.WaitGroup
wg.Add(opts.nbParrallelRequests)
for i := 0; i < opts.nbParrallelRequests; i++ {
wg.Add(opts.nbParallelRequests)
for i := 0; i < opts.nbParallelRequests; i++ {
go func(i int) {
test(handler, ts, i)
wg.Done()
Expand Down Expand Up @@ -850,7 +850,7 @@ func BenchmarkServerSuperGlobal(b *testing.B) {
cwd, _ := os.Getwd()
testDataDir := cwd + "/testdata/"

// Mimicks headers of a request sent by Firefox to GitHub
// Mimics headers of a request sent by Firefox to GitHub
headers := http.Header{}
headers.Add(strings.Clone("Accept"), strings.Clone("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"))
headers.Add(strings.Clone("Accept-Encoding"), strings.Clone("gzip, deflate, br"))
Expand Down
Loading

0 comments on commit 9a83ab1

Please sign in to comment.