<!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>Submits a task to a specific worker for execution</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pool.submit.html">Pool::submit</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mutex.html">Mutex</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.submitTo" class="refentry"> <div class="refnamediv"> <h1 class="refname">Pool::submitTo</h1> <p class="verinfo">(PECL pthreads >= 2.0.0)</p><p class="refpurpose"><span class="refname">Pool::submitTo</span> — <span class="dc-title">Submits a task to a specific worker for execution</span></p> </div> <div class="refsect1 description" id="refsect1-pool.submitTo-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::submitTo</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$worker</code></span> , <span class="methodparam"><span class="type"><a href="class.threaded.html" class="type Threaded">Threaded</a></span> <code class="parameter">$task</code></span> )</div> <p class="para rdfs-comment"> Submit a task to the specified worker in the pool. The workers are indexed from 0, and will only exist if the pool has needed to create them (since threads are lazily spawned). </p> </div> <div class="refsect1 parameters" id="refsect1-pool.submitTo-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">worker</code></dt> <dd> <p class="para"> The worker to stack the task onto, indexed from <em>0</em>. </p> </dd> <dt> <code class="parameter">task</code></dt> <dd> <p class="para"> The task for execution. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-pool.submitTo-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The identifier of the worker that accepted the task. </p> </div> <div class="refsect1 examples" id="refsect1-pool.submitTo-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4533"> <p><strong>Example #1 Submitting tasks to a specific worker</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Task </span><span style="color: #007700">extends </span><span style="color: #0000BB">Threaded </span><span style="color: #007700">{<br /> public function </span><span style="color: #0000BB">run</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">Thread</span><span style="color: #007700">::</span><span style="color: #0000BB">getCurrentThreadID</span><span style="color: #007700">());<br /> }<br />}<br /><br /></span><span style="color: #0000BB">$pool </span><span style="color: #007700">= new </span><span style="color: #0000BB">Pool</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">submit</span><span style="color: #007700">(new </span><span style="color: #0000BB">Task</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">5</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">submitTo</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, new </span><span style="color: #0000BB">Task</span><span style="color: #007700">()); </span><span style="color: #FF8000">// stack all tasks onto the first worker<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">$pool</span><span style="color: #007700">-></span><span style="color: #0000BB">submitTo</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, new </span><span style="color: #0000BB">Task</span><span style="color: #007700">()); </span><span style="color: #FF8000">// cannot stack the task onto the second worker due to it not existing yet<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 class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> int(4475011072) int(4475011072) int(4475011072) int(4475011072) int(4475011072) int(4475011072) Fatal error: Uncaught Exception: The selected worker (1) does not exist in %s:%d </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="pool.submit.html">Pool::submit</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mutex.html">Mutex</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>