简体   繁体   中英

How to serve php files using go's net/http package?

I want to a write a simple net/http.HandlerFunc which serves php files. Should I use net/http/cgi or net/http/fcgi , or is there a better way of running a php process?

From http://golang.org/pkg/net/http/fcgi/ :

Currently only the responder role is supported.

The Go FCGI package does not support calling other processes. It only knows how to serve requests when another server (such as nginx) connects. Therefore, your only option is CGI.


CGI is very inefficient and you should probably never use it. Instead, I recommend putting both your Go program and your PHP FCGI program behind a single reverse proxy such as Nginx.

Nginx has many great features including keep-alive timeouts that the default Go http server do not support. Using a reverse proxy adds features to your Go program and allows you to integrate other languages as well.

You can use this project

github.com/vanackere/gofcgisrv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM