Persistent streams are of type le_pstream, not le_stream. Therefore, the
persistent check will always be false. We can thus replace that check
with an assertion.
`zend_list_delete` removes the entry from the regular_list table, and
calls `zend_resource_dtor` via the table destructor.
When the refcount is 1, `zend_list_close` calls `zend_resource_dtor`,
but keeps the entry in the table.
Multiple calls to `zend_resource_dtor` have no effect: the destructor is
only called once.
Therefore, the `zend_list_close` operation is redundant because it is
fully included in the work done by `zend_list_delete`.
* 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
* 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
* major perf
* clean up before thread returns
* fix lint
* clean up and refactor server-context initialization
* removing the request-startup memset
I'm electing to remove the memset at startup and keeping it in shutdown. Why? Security! Keeping around the request data after a request may result in a leak of important information in a core dump or something. By setting it to zero when we shutdown the request, we can ensure no information is left laying around
* 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>