<!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>Collect references to completed tasks</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.pool.html">Pool</a></div> <div class="next" style="text-align: right; float: right;"><a href="pool.construct.html">Pool::__construct</a></div> <div class="up"><a href="class.pool.html">Pool</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="pool.collect" class="refentry"> <div class="refnamediv"> <h1 class="refname">Pool::collect</h1> <p class="verinfo">(PECL pthreads >= 2.0.0)</p><p class="refpurpose"><span class="refname">Pool::collect</span> — <span class="dc-title">Collect references to completed tasks</span></p> </div> <div class="refsect1 description" id="refsect1-pool.collect-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><strong>Pool::collect</strong></span> ([ <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type Callable">Callable</a></span> <code class="parameter">$collector</code></span> ] )</div> <p class="para rdfs-comment"> Allows the pool to collect references determined to be garbage by the optionally given collector. </p> </div> <div class="refsect1 parameters" id="refsect1-pool.collect-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">collector</code></dt> <dd> <p class="para"> A Callable collector that returns a boolean on whether the task can be collected or not. Only in rare cases should a custom collector need to be used. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-pool.collect-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The number of remaining tasks in the pool to be collected. </p> </div> <div class="refsect1 changelog" id="refsect1-pool.collect-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>v3</td> <td> An integer is now returned, and the <code class="parameter">collector</code> parameter is now optional. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-pool.collect-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4529"> <p><strong>Example #1 A basic example of <span class="methodname"><strong>Pool::collect()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$pool </span><span style="color: #007700">= new </span><span style="color: #0000BB">Pool</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /><br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">15</span><span style="color: #007700">; ++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">submit</span><span style="color: #007700">(new class extends </span><span style="color: #0000BB">Threaded </span><span style="color: #007700">{});<br />}<br /><br />while (</span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">collect</span><span style="color: #007700">()); </span><span style="color: #FF8000">// blocks until all tasks have finished executing<br /><br /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">shutdown</span><span style="color: #007700">();</span> </span> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.pool.html">Pool</a></div> <div class="next" style="text-align: right; float: right;"><a href="pool.construct.html">Pool::__construct</a></div> <div class="up"><a href="class.pool.html">Pool</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>