<!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>Creation</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="threaded.extend.html">Threaded::extend</a></div> <div class="next" style="text-align: right; float: right;"><a href="threaded.getterminationinfo.html">Threaded::getTerminationInfo</a></div> <div class="up"><a href="class.threaded.html">Threaded</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="threaded.from" class="refentry"> <div class="refnamediv"> <h1 class="refname">Threaded::from</h1> <p class="verinfo">(PECL pthreads >= 2.0.9)</p><p class="refpurpose"><span class="refname">Threaded::from</span> — <span class="dc-title">Creation</span></p> </div> <div id="threaded.from-refsynopsisdiv"> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> This method has been removed in pthreads v3. With the introduction of <a href="language.oop5.anonymous.html" class="link">anonymous classes</a> in PHP 7, these can now be used instead. </p> </div> </div> <div class="refsect1 description" id="refsect1-threaded.from-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><a href="class.threaded.html" class="type Threaded">Threaded</a></span> <span class="methodname"><strong>Threaded::from</strong></span> ( <span class="methodparam"><span class="type"><a href="class.closure.html" class="type Closure">Closure</a></span> <code class="parameter">$run</code></span> [, <span class="methodparam"><span class="type"><a href="class.closure.html" class="type Closure">Closure</a></span> <code class="parameter">$construct</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$args</code></span> ]] )</div> <p class="para rdfs-comment"> Creates an anonymous Threaded object from closures </p> </div> <div class="refsect1 parameters" id="refsect1-threaded.from-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">run</code></dt> <dd> <p class="para"> The closure to use for ::run </p> </dd> <dt> <code class="parameter">construct</code></dt> <dd> <p class="para"> The constructor to use for anonymous object </p> </dd> <dt> <code class="parameter">args</code></dt> <dd> <p class="para"> The arguments to pass to constructor </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-threaded.from-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> A new anonymous Threaded object </p> </div> <div class="refsect1 examples" id="refsect1-threaded.from-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4496"> <p><strong>Example #1 Thread safe objects from closures</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 /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">submit</span><span style="color: #007700">(</span><span style="color: #0000BB">Collectable</span><span style="color: #007700">::</span><span style="color: #0000BB">from</span><span style="color: #007700">(function(){<br /> echo </span><span style="color: #DD0000">"Hello World"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">setGarbage</span><span style="color: #007700">();<br />}));<br /></span><span style="color: #FF8000">/* ... */<br /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">shutdown</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Hello World </pre></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="threaded.extend.html">Threaded::extend</a></div> <div class="next" style="text-align: right; float: right;"><a href="threaded.getterminationinfo.html">Threaded::getTerminationInfo</a></div> <div class="up"><a href="class.threaded.html">Threaded</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>