内部 Apache 请求 PHP 脚本的开销
我有一个 PHP 页面,它通过使用 file_get_contents
向同一服务器上的另一个站点发出 HTTP 请求来获取其内容。这两个站点都在 Apache 2 中运行,该 Apache 2 使用 suPHP(即 FastCGI,对吧?)调用 PHP。
此调用的开销有多大? Apache 在向 PHP 发送请求之前是否会进行大量处理?
进行调用的另一种方法是第一个站点执行 exec('php /the/other/script.php someparameters')
。这会更快吗?或者生成进程的开销是否比通过 Apache 的开销更大?
I have a PHP page that gets its content by making an HTTP request to another site on the same server, using file_get_contents
. Both sites run in Apache 2 which calls PHP using suPHP (which is FastCGI, right?)
How significant is the overhead of this call? Does Apache do a lot of processing before sending a request to PHP?
An alternative way to make the call would be for the first site to exec('php /the/other/script.php some parameters')
. Would this be faster, or is the overhead of spawning a process bigger than that of going through Apache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache 的开销将取决于该站点主机的配置,例如 https、htaccess 检查、重写等。这些东西可以叠加。现在,我认为相对而言,这不会造成太大的压力,但是您将需要时间来生成响应,这取决于外部页面的性质,在某些情况下调用可能会很重要。
话虽如此,我并不认为通过 apache 进行调用有问题。但我确实认为,正如您建议的那样,直接公开 php 会更好。我认为也许阅读一般的 SOA 可能会帮助您深入了解如何最好地实施。
Apache's over head is going to depend on whats configured for that site host, for example https, htaccess checks, rewriting, etc.. Those things can stack up. Now i dont think it would be much strain overhead wise comparatively but you are going to have the time it taks to generate the response which depending on the nature of the external pages oyure calling could be signifigant in some situations.
With that said, i dont nessecarily see a problem with making the calls through apache. But i do think that as you suggest exposing the php directly would be better. I think maybe reading up on SOA in general might help you gain some insight on how best to implement.
不幸的是,将 PHP 安装为 cgi,您将损失大量性能,因为每次您都必须为其创建一个新进程。
所以最好的方法是将 PHP 安装为 apache 模块
Unfotunatly installing PHP as cgi, you will loose alot of performace, because eachtime you have to create a new process for it.
So best method is to install PHP as apache modul