uTools-Manuals/docs/php/curl_multi_info_read.html
2019-04-28 19:00:34 +08:00

193 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>获取当前解析的cURL的相关传输信息</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.curl-multi-info-read" class="refentry">
<div class="refnamediv">
<h1 class="refname">curl_multi_info_read</h1>
<p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">curl_multi_info_read</span> &mdash; <span class="dc-title">获取当前解析的cURL的相关传输信息</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.curl-multi-info-read-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>curl_multi_info_read</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$mh</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$msgs_in_queue</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
查询批处理句柄是否单独的传输线程中有消息或信息返回。消息可能包含诸如从单独的传输线程返回的错误码或者只是传输线程有没有完成之类的报告。
</p>
<p class="para">
重复调用这个函数,它每次都会返回一个新的结果,直到这时没有更多信息返回时,<strong><code>FALSE</code></strong> 被当作一个信号返回。通过<code class="parameter">msgs_in_queue</code>返回的整数指出将会包含当这次函数被调用后,还剩余的消息数。
</p>
<div class="warning"><strong class="warning">Warning</strong>
<p class="para">
返回的资源指向的数据调用<span class="function"><a href="curl_multi_remove_handle.html" class="function">curl_multi_remove_handle()</a></span>后将不会存在。
</p>
</div>
</div>
<div class="refsect1 parameters" id="refsect1-function.curl-multi-info-read-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">mh</code>
</dt>
<dd>
<p class="para"><span class="function"><a href="curl_multi_init.html" class="function">curl_multi_init()</a></span> 返回的 cURL 多个句柄。</p></dd>
<dt>
<code class="parameter">msgs_in_queue</code></dt>
<dd>
<p class="para">
仍在队列中的消息数量。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.curl-multi-info-read-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回相关信息的数组,失败时返回<strong><code>FALSE</code></strong>
</p>
<p class="para">
<table class="doctable table">
<caption><strong>返回数组的内容</strong></caption>
<thead>
<tr>
<th>Key:</th>
<th>Value:</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td><em>msg</em></td>
<td><strong><code>CURLMSG_DONE</code></strong>常量。其他返回值当前不可用。</td>
</tr>
<tr>
<td><em>result</em></td>
<td><strong><code>CURLE_*</code></strong>常量之一。如果一切操作没有问题,将会返回<strong><code>CURLE_OK</code></strong>常量。</td>
</tr>
<tr>
<td><em>handle</em></td>
<td>cURL资源类型表明它有关的句柄。</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.curl-multi-info-read-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5246">
<p><strong>Example #1 一个<span class="function"><strong>curl_multi_info_read()</strong></span>范例</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$urls&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"http://www.cnn.com/"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"http://www.bbc.co.uk/"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"http://www.yahoo.com/"<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$mh&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_multi_init</span><span style="color: #007700">();<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$urls&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$url</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">CURLOPT_RETURNTRANSFER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">curl_multi_add_handle</span><span style="color: #007700">(</span><span style="color: #0000BB">$mh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />}<br /><br />do&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$status&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_multi_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$mh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$active</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_multi_info_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$mh</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$info</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;while&nbsp;(</span><span style="color: #0000BB">$status&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">CURLM_CALL_MULTI_PERFORM&nbsp;</span><span style="color: #007700">||&nbsp;</span><span style="color: #0000BB">$active</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$urls&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$url</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">curl_multi_getcontent</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">curl_multi_info_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$mh</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
[&quot;msg&quot;]=&gt;
int(1)
[&quot;result&quot;]=&gt;
int(0)
[&quot;handle&quot;]=&gt;
resource(5) of type (curl)
}
array(3) {
[&quot;msg&quot;]=&gt;
int(1)
[&quot;result&quot;]=&gt;
int(0)
[&quot;handle&quot;]=&gt;
resource(7) of type (curl)
}
array(3) {
[&quot;msg&quot;]=&gt;
int(1)
[&quot;result&quot;]=&gt;
int(0)
[&quot;handle&quot;]=&gt;
resource(6) of type (curl)
}
bool(false)
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.curl-multi-info-read-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.2.0</td>
<td>
<code class="parameter">msgs_in_queue</code>被加入。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.curl-multi-info-read-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="curl_multi_init.html" class="function" rel="rdfs-seeAlso">curl_multi_init()</a> - 返回一个新cURL批处理句柄</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>