PHP file_get_contents('php://input')非常慢 [英] PHP file_get_contents('php://input') very slow

查看:145
本文介绍了PHP file_get_contents('php://input')非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的PHP应用程序,该应用程序使用由Zend Framework v1.x构建的ESB模型.性能已经成为一个问题,现在我知道为什么了:读取php://input流始终需要差不多10秒的时间.

I have a complex PHP application that uses an ESB model built with Zend Framework v1.x. Performance has become an issue, and now I know why: reading the php://input stream is consistently taking almost exactly 10 seconds.

这是XDebug跟踪日志的摘录:

Here is a snippet from an XDebug trace log:

0.3985    6935880    -> Zend_Controller_Request_Http->getRawBody() /var/www/vas/Adapters/Database/application/controllers/AdapterController.php:473
0.3985    6936104    -> file_get_contents() /usr/share/php/ZendFramework-1.12.0/library/Zend/Controller/Request/Http.php:961
10.4134   6936096    -> trim() /usr/share/php/ZendFramework-1.12.0/library/Zend/Controller/Request/Http.php:963

我们部署了一个ESB模型,其中请求从门户到ESB,再到数据库适配器.单独击中任何一台服务器似乎没有问题,但是,只要请求在服务器之间(实际上是同一台服务器上的虚拟主机)之间进行,问题就会自动出现.

We deploy a ESB model, with requests going fro the portal, to the ESB, to the data base adapter. Hitting any one server by itself doesn't seem to be problematic, but as soon as the request goes between servers (which are actually vhosts on the same server), the problem rears itself.

推荐答案

事实证明,这是Apache httpd或PHP中的错误,也是Zend Framework v 1.x中的错误.

It turns out this is a bug in either Apache httpd or PHP, as well as a bug in Zend Framework v 1.x.

当内容长度标头的值超过实际内容长度时,就会发生该错误.

The bug occurs when a content-length header's value exceeds the actual content length.

例如,

curl http://localhost/index.php -H "Content-Length: 3" --data "12"

在上面的示例中,必须在调用file_get_contents('php://input')之后达到10秒钟的超时时间,然后才能返回请求正文.

In the above example, a 10 second timeout must be reached after calling file_get_contents('php://input') before the request body is returned.

在Zend Framework v1.x中,设置Zend_HTTP_Client对象的原始主体会导致计算Content-Length标头并将其注入到请求中.但是,除非该请求是POST,PUT或DELETE请求,否则实际请求中的内容将被省略,从而触发Apache/PHP无效内容长度错误.

In Zend Framework v1.x, setting the raw body of a Zend_HTTP_Client object causes a Content-Length header to be calculated and injected into the request. However, unless the request is a POST, PUT or DELETE request, the content will be omitted from the actual request, which, in turn, triggers the Apache/PHP invalid-content-length bug.

我已经用PHP打开了一个错误,并且还将用Zend Framework打开了一个错误.

I have opened a bug with PHP and will also open a bug with Zend Framework.

这篇关于PHP file_get_contents('php://input')非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆