As discussed in https://github.com/php/frankenphp/discussions/1961,
there is no real way to pass a severity/level to any log handler offered
by PHP that would make it to the FrankenPHP layer. This new function
allows applications embedding FrankenPHP to integrate PHP logging into
the application itself, thus offering a more streamlined experience.
---------
Co-authored-by: Quentin Burgess <qutn.burgess@gmail.com>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
This PR:
- moves state.go to its own module
- moves the phpheaders test the phpheaders module
- simplifies backoff.go
- makes the backoff error instead of panic (so it can be tested)
- removes some unused C structs
* delete source/downloads after building in script, not in dockerfile
* add editorconfig
* eol
* cs fix
* added \n there
* we expect Hello\n
* Change tab width for shell scripts to 4 spaces
* bring back embed comment
* add module (php_server directive) based workers
* refactor moduleID to uintptr for faster comparisons
* let workers inherit environment variables and root from php_server
* caddy can shift FrankenPHPModules in memory for some godforsaken reason, can't rely on them staying the same
* remove debugging statement
* fix tests
* refactor moduleID to uint64 for faster comparisons
* actually allow multiple workers per script filename
* remove logging
* utility function
* reuse existing worker with same filename and environment when calling newWorker with a filepath that already has a suitable worker, simply add number of threads
* no cleanup happens between tests, so restore old global worker overwriting logic
* add test, use getWorker(ForContext) function in frankenphp.go as well
* bring error on second global worker with the same filename again
* refactor to using name instead of moduleID
* nicer name
* nicer name
* add more tests
* remove test case already covered by previous test
* revert back to single variable, moduleIDs no longer relevant
* update comment
* figure out the worker to use in FrankenPHPModule::ServeHTTP
* add caddy/config_tests, add --retry 5 to download
* add caddy/config_tests
* sum up logic a bit, put worker thread addition into moduleWorkers parsing, before workers are actually created
* implement suggestions as far as possible
* fixup
* remove tags
* feat: download the mostly static binary when possible (#1467)
* feat: download the mostly static binary when possible
* cs
* docs: remove wildcard matcher from root directive (#1513)
* docs: update README with additional documentation links
Add link to classic mode, efficiently serving large static files and monitoring FrankenPHP
Signed-off-by: Romain Bastide <romain.bastide@orange.com>
* ci: combine dependabot updates for one group to 1 pull-request
* feat: compatibility with libphp.dylib on macOS
* feat: upgrade to Caddy 2.10
* feat: upgrade to Caddy 2.10
* chore: run prettier
* fix: build-static.sh consecutive builds (#1496)
* fix consecutive builds
* use minor version in PHP_VERSION
* install jq in centos container
* fix "arm64" download arch for spc binary
* jq is not available as a rpm download
* linter
* specify php 8.4 default
specify 8.4 so we manually switch to 8.5 when we make sure it works
allows to run without jq installed
* Apply suggestions from code review
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
---------
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
* chore: update Go and toolchain version (#1526)
* apply suggestions one be one - scriptpath only
* generate unique worker names by filename and number
* support worker config from embedded apps
* rename back to make sure we don't accidentally add FrankenPHPApp workers to the slice
* fix test after changing error message
* use 🧩 for module workers
* use 🌍 for global workers :)
* revert 1c414cebbc
* revert 4cc8893ced
* apply suggestions
* add dynamic config loading test of module worker
* fix test
* minor changes
---------
Signed-off-by: Romain Bastide <romain.bastide@orange.com>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
Co-authored-by: Indra Gunawan <hello@indra.my.id>
Co-authored-by: Romain Bastide <romain.bastide@orange.com>
* fix a memory leak on thread shutdown
* clean up unused resources at end of request
* try the obvious
* Test
* clang-format
* Also ignores persistent streams.
* Adds stream test.
* Moves clean up function to frankenphp_worker_request_shutdown.
* Fixes test on -nowatcher
* Fixes test on -nowatcher
* Update testdata/file-stream.txt
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
* Update frankenphp_test.go
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
---------
Co-authored-by: Alliballibaba <alliballibaba@gmail.com>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
* Puts everything into one function call.
* Clang-format off.
* Cleans up.
* Changes function name.
* Removes unnecessary check.
* Passes hash table directly.
* Also tests that the original request path is passed.
* Puts vars into a struct.
* clang-format
---------
Co-authored-by: Alliballibaba <alliballibaba@gmail.com>
* Decouple workers.
* Moves code to separate file.
* Cleans up the exponential backoff.
* Initial working implementation.
* Refactors php threads to take callbacks.
* Cleanup.
* Cleanup.
* Cleanup.
* Cleanup.
* Adjusts watcher logic.
* Adjusts the watcher logic.
* Fix opcache_reset race condition.
* Fixing merge conflicts and formatting.
* Prevents overlapping of TSRM reservation and script execution.
* Adjustments as suggested by @dunglas.
* Adds error assertions.
* Adds comments.
* Removes logs and explicitly compares to C.false.
* Resets check.
* Adds cast for safety.
* Fixes waitgroup overflow.
* Resolves waitgroup race condition on startup.
* Moves worker request logic to worker.go.
* Removes defer.
* Removes call from go to c.
* Fixes merge conflict.
* Adds fibers test back in.
* Refactors new thread loop approach.
* Removes redundant check.
* Adds compareAndSwap.
* Refactor: removes global waitgroups and uses a 'thread state' abstraction instead.
* Removes unnecessary method.
* Updates comment.
* Removes unnecessary booleans.
* test
* First state machine steps.
* Splits threads.
* Minimal working implementation with broken tests.
* Fixes tests.
* Refactoring.
* Fixes merge conflicts.
* Formatting
* C formatting.
* More cleanup.
* Allows for clean state transitions.
* Adds state tests.
* Adds support for thread transitioning.
* Fixes the testdata path.
* Formatting.
* Allows transitioning back to inactive state.
* Fixes go linting.
* Formatting.
* Removes duplication.
* Applies suggestions by @dunglas
* Removes redundant check.
* Locks the handler on restart.
* Removes unnecessary log.
* Changes Unpin() logic as suggested by @withinboredom
* Adds suggestions by @dunglas and resolves TODO.
* Makes restarts fully safe.
* Will make the initial startup fail even if the watcher is enabled (as is currently the case)
* Also adds compareAndSwap to the test.
* Adds comment.
* Prevents panic on initial watcher startup.
* implement getenv and putenv in go
* fix typo
* apply formatting
* return a bool
* prevent ENV= from crashing
* optimization
* optimization
* split env workflows and use go_strings
* clean up unused code
* update tests
* remove useless sprintf
* see if this fixes the asan issues
* clean up comments
* check that VAR= works correctly and use actual php to validate the behavior
* move all unpinning to the end of the request
* handle the case where php is not installed
* fix copy-paste
* optimization
* use strings.cut
* fix lint
* override how env is filled
* reuse fullenv
* use corect function
* Removes the worker panic when the watcher is enabled.
* Only panics on the initial boot.
* Only panics on the initial boot.
* Resets to always panic when watcher is disabled.
---------
Co-authored-by: a.stecher <a.stecher@sportradar.com>
* handle failures gracefully
* fix super-subtle race condition
* address feedback: panic instead of fatal log and make vars into consts
* pass the frankenphp context to worker-ready function
* reset backoff and failures on normal restart
* update docs
* add test and fix race condition
* fail sometimes but do not be pathological about it
* Use title case
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
* fix code style in php
* define lifecycle metrics
* ensure we update unregister the metrics and fix tests
* update caddy tests and fix typo
* update docs
* no need for this
---------
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
* fix: reset sapi response code
It turns out that the sapi response code is NOT reset between requests by the zend engine. This resets the code for cgi-based requests.
fixes: #960
* update response header test
* fix assertion
* appears to affect workers too
* test: failing test reproducing #767
* fix
* Update frankenphp.c
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
* Update frankenphp.c
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
* review
* ZVAL_COPY
* fix
* add back current $_SERVER behavior
* add docs
* bad fix for the leak
* clean test
* improve tests
* fix test
* fix
* cleanup
* clarify destroy super globals name
* micro-optim: use zval_ptr_dtor_nogc to destroy super globals
* style
* fix
* better name for frankenphp_free_server_context
* more cleanup
* remove useless memset
* more cleanup
* continue refactoring
* fix and update docs
* docs
---------
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
* feat(caddy): a command to start a PHP server
* docs and l shortcut
* fix some bugs and support for compression
* cleanup
* enable compression by default
* add -a shortcut
* refactor
* const
* docs