如果$ ch没准备好,curl_multi_getcontent($ ch)会返回什么?

Kea*_*her 1 php curl

如果$ ch在PHP中没有准备好,curl_multi_getcontent($ ch)会返回什么?

gro*_*gel 5

你问的问题的答案是

  • 如果尚未收到回复,则curl_multi_getcontent返回NULL.
  • 如果传输正在进行中,则curl_multi_getcontent返回到目前为止检索的数据.


显然,你要问的问题是:我怎么知道一个curl_multi...操作什么时候结束?

The answer is that you don't use curl_multi_getcontent for this. Instead, repeatedly call curl_multi_exec until the second parameter (which is the number of sub-handles still working on its transfer) goes to 0. This blog post, from the comments in the manual, shows some working code. You may also want to look at curl_multi_select, which will block until there's some activity on a connection. This probably leads to fewer cycles wasted making curl_multi_exec calls: See example #1 on the manual page for curl_multi_exec.

If you're using version 5.2.0 or later, you can use curl_multi_info_read to get the status of individual connections instead of waiting for all of them. (manual)