问题描述
我需要对服务器执行RAW POST(PUT $ var)请求,并将该页面的结果作为字符串接受。还需要添加自定义HTTP标头信息(如x-example-info:2342342)
I have a need to do RAW POST (PUT a $var) requests to a server, and accept the results from that page as a string. Also need to add custom HTTP header information (like x-example-info: 2342342)
我有两种方法可以做到这一点
I have two ways of doing it
- 卷曲()
- 使用HTTPRequest的PHP HTTP()
- Curl (http://us.php.net/manual/en/book.curl.php)
- PHP HTTP using the HTTPRequest (http://us.php.net/manual/en/book.http.php)
两者有什么区别?什么更精益?更快?对我来说两者看起来都差不多......
What are the differences between the two? what's more lean? faster? Both seem pretty much the same to me...
推荐答案
Curl与PHP捆绑在一起,HTTPRequest是一个单独的PECL扩展。
Curl is bundled with PHP, HTTPRequest is a separate PECL extension.
因此,更有可能在目标平台上安装CURL,这几乎是大多数项目的决定性因素。如果您计划只在您个人能够安装PECL扩展的服务器上安装您的软件,我只考虑使用HTTPRequest;如果您的客户将进行自己的安装,那么安装PECL扩展通常是不可能的。
As such, it's much more likely that CURL will be installed on your target platform, which is pretty much the deciding factor for most projects. I'd only consider using HTTPRequest if you plan to only ever install your software on servers you personally have the ability to install PECL extensions on; if your clients will be doing their own installations, installing PECL extensions is usually out of the question.
似乎暗示HTTPRequest无论如何都使用了引擎盖下的CURL。听起来它可能会为curl_multi _ *()提供更优雅的界面。
This page seems to suggest that HTTPRequest uses CURL under the hood anyway. Sounds like it might offer a slightly more elegant interface to curl_multi_*(), though.
这篇关于PHP在Curl和HttpRequest之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!