PHP CURL api 是否比使用流进行 HTTP/HTTPS 访问更干净/更快/更好?
我目前只使用 PHP 流上下文功能(请参阅 https: //www.php.net/manual/en/function.stream-context-create.php) 来访问 HTTP 资源,我已经能够成功地使用它来执行 PUT、DELETE、POST、管理 cookie并做几乎所有事情我需要做的。我最初开始使用它是因为我在早期的 Debian PHP cURL 版本中遇到了 SSL 问题(Apache 进程中存在 OpenSSL 双重初始化问题,在尝试访问 SSL url 时出错):这些问题现在可能已修复,但我还没有修复有机会回去。
在与朋友的讨论中,他认为 cURL api 更快/更好,所以我想问:是否有任何明确的经验/知识关于哪个选项更优越,以及在哪些方面?
I currently use pretty exclusively the PHP stream context functionality (see https://www.php.net/manual/en/function.stream-context-create.php) to access HTTP resources and I've been able to successfully use it to do PUTs, DELETEs, POSTs, manage cookies and do just about everything I've needed to do. I originally started using it because I had SSL issues with earlier Debian PHP cURL builds (there was an OpenSSL double-initialization issue within the Apache process that errored out when trying to access SSL urls): those are probably fixed now but I've not had occasion to go back.
In discussions with a friend he contended that the cURL api is faster/better so I wanted to ask: is there any definite experience/knowledge about which option is superior, and in what ways?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,流非常整洁。您可能已经知道了,但这里有一篇关于流的文章,以防万一不知道:
http://fabien.potencier.org/article/44/php-iterators-and-streams-are-awesome
Curl 很好、快速、简单;但老实说,出于性能原因,我不喜欢其中之一。我从未测量过,但我怀疑它与一开始执行远程请求的开销相比有那么大的差异。
Streams are pretty neat in my experience. You probably know it already, but here's a post on streams with a twist in case not:
http://fabien.potencier.org/article/44/php-iterators-and-streams-are-awesome
Curl is nice and fast, and simple; but I honestly wouldn't prefer one or the other for performance reasons. I've never measured but I doubt it makes that much of a difference in comparison with the overhead of doing a remote request in the first place.
在性能方面,cURL 胜出
很多< /罢工>始终如一。我不会否认它更难使用,并且对于一般用途来说可能并不重要,但差异非常显着,我认为值得指出。In regards to performance, cURL wins
by a lotconsistently. I won't deny that it's harder to use and it might not matter for general use, but the difference was pretty dramatic and I thought it was worth pointing out.