mirror of
https://github.com/dunglas/frankenphp
synced 2024-11-22 16:19:32 +00:00
docs: add examples
This commit is contained in:
parent
8c87075db8
commit
2b3475ed9d
@ -306,7 +306,7 @@ func testPhpInfo(t *testing.T, scriptName string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Example() {
|
||||
func ExampleExecuteScript() {
|
||||
frankenphp.Startup()
|
||||
defer frankenphp.Shutdown()
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user