-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathphp.go
47 lines (43 loc) · 1.61 KB
/
php.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package php
import (
"net/http"
"github.com/yookoala/gofast"
)
// NewSimpleHandler returns a fastcgi web server implementation as an http.Handler
// that functions like a traditional file based PHP hosting.
//
// Please note that this handler doesn't handle the fastcgi application process.
// You'd need to start it with other means.
//
// docroot: the document root of the PHP site.
// network: network protocol (tcp / tcp4 / tcp6)
// or if it is a unix socket, "unix"
// address: IP address and port, or the socket physical address of the fastcgi
// application.
func NewSimpleHandler(docroot, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
h := gofast.NewHandler(
gofast.NewPHPFS(docroot)(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory),
)
return h
}
// NewFileEndpointHandler returns a fastcgi web server implementation as an
// http.Handler that referers to a single backend PHP script.
//
// Please note that this handler doesn't handle the fastcgi application process.
// You'd need to start it with other means.
//
// filepath: the path to the endpoint PHP file.
// network: network protocol (tcp / tcp4 / tcp6)
// or if it is a unix socket, "unix"
// address: IP address and port, or the socket physical address of the fastcgi
// application.
func NewFileEndpointHandler(filepath, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
h := gofast.NewHandler(
gofast.NewFileEndpoint(filepath)(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory),
)
return h
}