docs: add examples

This commit is contained in:
Kévin Dunglas 2022-05-20 09:42:30 +02:00
parent 8c87075db8
commit 2b3475ed9d
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
2 changed files with 20 additions and 1 deletions

View File

@ -306,7 +306,7 @@ func testPhpInfo(t *testing.T, scriptName string) {
}
}
func Example() {
func ExampleExecuteScript() {
frankenphp.Startup()
defer frankenphp.Shutdown()

View File

@ -3,11 +3,14 @@ package frankenphp_test
import (
"fmt"
"io"
"log"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/dunglas/frankenphp"
"github.com/stretchr/testify/assert"
)
@ -40,3 +43,19 @@ func TestWorker(t *testing.T) {
assert.Contains(t, string(body2), fmt.Sprintf("Requests handled: %d", i*2+1))
}
}
func ExampleWorkerHandleRequest() {
frankenphp.Startup()
defer frankenphp.Shutdown()
frankenphp.StartWorkers("worker.php", 5)
phpHandler := func(w http.ResponseWriter, req *http.Request) {
if err := frankenphp.WorkerHandleRequest(w, req); err != nil {
log.Print(fmt.Errorf("error executing PHP script: %w", err))
}
}
http.HandleFunc("/", phpHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}