CURL与fsockopen分块

问题描述:

这似乎有点奇怪。.但我需要评估/解析使用PHP通过HTTP发送的块。

This may seem kind of weird.. but I need to evaluate/parse chunks being sent over HTTP with PHP.

值得注意的是,HTTP流可能永远不会结束。我可以通过CURL解析获取它们时的任何方法吗?

It's of note to say that the HTTP stream may never end. Is there any way I can parse chunks as I get them with CURL?

还是我不得不求助于一些自制的 fsockopen()解决方案?

Or do I have to resort to some home-brewed fsockopen() solution?

看看选项 CURLOPT_WRITEFUNCTION 。您可以定义一个回调,当响应中有新数据时将调用该回调。参见手册

Take a look at the option CURLOPT_WRITEFUNCTION. You can define a callback that will be called when there's new data in the response. See the manual.