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

huangapple go评论94阅读模式
英文:

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

问题

我想编写一个简单的 net/http.HandlerFunc,用于提供 PHP 文件。我应该使用 net/http/cgi 还是 net/http/fcgi,或者有其他更好的运行 PHP 进程的方法吗?

英文:

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?

答案1

得分: 5

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

目前只支持响应者角色。

Go FCGI包不支持调用其他进程。它只知道在另一个服务器(如nginx)连接时如何提供请求。因此,您的唯一选择是CGI。


CGI非常低效,您可能永远不应该使用它。相反,我建议将您的Go程序和PHP FCGI程序都放在一个单独的反向代理(如Nginx)后面。

Nginx具有许多出色的功能,包括默认的Go http服务器不支持的保持活动超时。使用反向代理可以为您的Go程序添加功能,并允许您集成其他语言。

英文:

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.

答案2

得分: 2

你可以使用这个项目:

github.com/vanackere/gofcgisrv

英文:

You can use this project

> github.com/vanackere/gofcgisrv

huangapple
  • 本文由 发表于 2013年8月19日 12:19:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/18306330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定