docs: add an exemple

This commit is contained in:
Kévin Dunglas 2022-05-19 17:42:12 +02:00
parent 9761090c06
commit 8c87075db8
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"log"
"net/http"
"net/http/cookiejar"
"net/http/httptest"
@ -304,3 +305,17 @@ func testPhpInfo(t *testing.T, scriptName string) {
assert.Contains(t, string(body), "frankenphp")
}
}
func Example() {
frankenphp.Startup()
defer frankenphp.Shutdown()
phpHandler := func(w http.ResponseWriter, req *http.Request) {
if err := frankenphp.ExecuteScript(w, req); err != nil {
log.Print(fmt.Errorf("error executing PHP script: %w", err))
}
}
http.HandleFunc("/", phpHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}