From 82ef1e868d8eac963001bf2ad80887476798ed9a Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Thu, 10 Nov 2022 06:44:52 +0100 Subject: [PATCH] Fix #46 This is the bare minimum required to make fibers work within the go runtime. --- frankenphp.go | 1 + frankenphp_test.go | 17 +++++++++++++++++ testdata/fiber-basic.php | 10 ++++++++++ 3 files changed, 28 insertions(+) create mode 100644 testdata/fiber-basic.php diff --git a/frankenphp.go b/frankenphp.go index c3031eecb..d3aa7e0b6 100644 --- a/frankenphp.go +++ b/frankenphp.go @@ -9,6 +9,7 @@ package frankenphp //go:generate rm -rf C-Thread-Pool/.git C-Thread-Pool/.circleci C-Thread-Pool/docs C-Thread-Pool/tests // #cgo CFLAGS: -Wall +// #cgo CFLAGS: -fsplit-stack // #cgo CFLAGS: -I/usr/local/include/php -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -I/usr/local/include/php/main // #cgo LDFLAGS: -L/usr/local/lib -L/opt/homebrew/opt/libiconv/lib -L/usr/lib -lphp -lxml2 -lresolv -lsqlite3 -ldl -lm -lutil // #cgo darwin LDFLAGS: -liconv diff --git a/frankenphp_test.go b/frankenphp_test.go index c30d478d4..1e5e0cd7f 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -536,6 +536,23 @@ func testEarlyHints(t *testing.T, opts *testOptions) { }, opts) } +func TestFiberBasic_module(t *testing.T) { testFiberBasic(t, &testOptions{}) } +func TestFiberBasic_worker(t *testing.T) { + testFiberBasic(t, &testOptions{workerScript: "fiber-basic.php"}) +} +func testFiberBasic(t *testing.T, opts *testOptions) { + runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { + req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/fiber-basic.php?i=%d", i), nil) + w := httptest.NewRecorder() + handler(w, req) + + resp := w.Result() + body, _ := io.ReadAll(resp.Body) + + assert.Contains(t, string(body), "OK") + }, opts) +} + type streamResponseRecorder struct { *httptest.ResponseRecorder writeCallback func(buf []byte) diff --git a/testdata/fiber-basic.php b/testdata/fiber-basic.php new file mode 100644 index 000000000..eef6a1b74 --- /dev/null +++ b/testdata/fiber-basic.php @@ -0,0 +1,10 @@ +start(); +}; +