|
|
<html> |
|
|
<head> |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
|
<title>Chapter 1. ZendX_Console_Process_Unix</title> |
|
|
<link rel="stylesheet" type="text/css" href="dbstyle.css"> |
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> |
|
|
<link rel="home" href="index.html" title="Programmer's Reference Guide"> |
|
|
<link rel="up" href="index.html" title="Programmer's Reference Guide"> |
|
|
<link rel="prev" href="index.html" title="Programmer's Reference Guide"> |
|
|
<link rel="next" href="zendx.jquery.html" title="Chapter 2. ZendX_JQuery"> |
|
|
<link rel="chapter" href="zendx.console.process.unix.html" title="Chapter 1. ZendX_Console_Process_Unix"> |
|
|
<link rel="chapter" href="zendx.jquery.html" title="Chapter 2. ZendX_JQuery"> |
|
|
<link rel="index" href="the.index.html" title="Index"> |
|
|
</head> |
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
|
|
<div class="navheader"><table width="100%" summary="Navigation header"> |
|
|
<tr><th colspan="3" align="center">Chapter 1. ZendX_Console_Process_Unix</th></tr> |
|
|
<tr> |
|
|
<td width="20%" align="left"> |
|
|
<a accesskey="p" href="index.html">Prev</a> </td> |
|
|
<th width="60%" align="center"> </th> |
|
|
<td width="20%" align="right"> <a accesskey="n" href="zendx.jquery.html">Next</a> |
|
|
</td> |
|
|
</tr> |
|
|
</table></div> |
|
|
<div class="chapter"> |
|
|
<div class="titlepage"><div><div><h1 class="title"> |
|
|
<a name="zendx.console.process.unix"></a>Chapter 1. ZendX_Console_Process_Unix</h1></div></div></div> |
|
|
<span style="color: red"><sect1> |
|
|
<span style="color: red"><title>ZendX_Console_Process_Unix</title></span> |
|
|
|
|
|
<span style="color: red"><sect2> |
|
|
<span style="color: red"><title>Introduction</title></span> |
|
|
<span style="color: red"><para> |
|
|
<span style="color: red"><classname>ZendX_Console_Process_Unix</classname></span> allows developers to spawn |
|
|
an object as a new process, and so do multiple tasks in parallel on |
|
|
console environments. Through its specific nature, it is only |
|
|
working on *nix based systems like Linux, Solaris, Mac/OSx and such. |
|
|
Additionally, the <span style="color: red"><code>shmop_*</code></span>, <span style="color: red"><code>pcntl_*</code></span> and |
|
|
<span style="color: red"><code>posix_*</code></span> modules are required for this component to |
|
|
run. If one of the requirements is not met, it will throw an |
|
|
exception after instantiating the component. |
|
|
</para></span> |
|
|
</sect2></span> |
|
|
|
|
|
<span style="color: red"><sect2> |
|
|
<span style="color: red"><title>Basic usage of ZendX_Console_Process_Unix</title></span> |
|
|
<span style="color: red"><para> |
|
|
<span style="color: red"><classname>ZendX_Console_Process_Unix</classname></span> is an abstract class, which |
|
|
requires the user to extend it. It has a single abstract method |
|
|
called <span style="color: red"><methodname>_run()</methodname></span> which has to be implemented to create a |
|
|
working process. It also comes with multiple methods for checking |
|
|
the alive status and share variables between the parent and the |
|
|
child process. |
|
|
</para></span> |
|
|
|
|
|
<span style="color: red"><para> |
|
|
The <span style="color: red"><methodname>_run()</methodname></span> method and every method which is called |
|
|
by it is executed by the child process. Every other method which is |
|
|
called directly by the parent is executed by the parent process. |
|
|
</para></span> |
|
|
|
|
|
<span style="color: red"><para> |
|
|
<span style="color: red"><methodname>setVariable()</methodname></span> and <span style="color: red"><methodname>getVariable()</methodname></span> can be |
|
|
used from both the parent- and the child process to share variables. |
|
|
To observe the alive status, the child process should call |
|
|
<span style="color: red"><methodname>_setAlive()</methodname></span> in a frequent interval, so that the parent |
|
|
process can check the last alive time via <span style="color: red"><methodname>getLastAlive()</methodname></span>. |
|
|
To get the PID of the child process, the parent can call |
|
|
<span style="color: red"><methodname>getPid()</methodname></span>. |
|
|
</para></span> |
|
|
|
|
|
<span style="color: red"><example> |
|
|
<span style="color: red"><title>Basic example for processing</title></span> |
|
|
<span style="color: red"><para> |
|
|
This example illustrates a basic child process |
|
|
</para></span> |
|
|
|
|
|
<span style="color: red"><programlisting> |
|
|
class MyProcess extends ZendX_Console_Process_Unix |
|
|
{ |
|
|
protected function _run() |
|
|
{ |
|
|
for ($i = 0; $i < 10; $i++) { |
|
|
// Doing something really important which can't wait: sleeping |
|
|
sleep(1); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// This part should last about 10 seconds, not 20. |
|
|
$process1 = new MyProcess(); |
|
|
$process1->start(); |
|
|
|
|
|
$process2 = new MyProcess(); |
|
|
$process2->start(); |
|
|
|
|
|
while ($process1->isRunning() || $process2->isRunning()) { |
|
|
sleep(1); |
|
|
} |
|
|
|
|
|
echo 'All processes completed'; |
|
|
</programlisting></span> |
|
|
|
|
|
<span style="color: red"><para> |
|
|
In this example a process is forked twice and executed. As every |
|
|
process runs 10 seconds, the parent process will be finished after |
|
|
10 seconds (and not 20). |
|
|
</para></span> |
|
|
</example></span> |
|
|
|
|
|
</sect2></span> |
|
|
</sect1></span> |
|
|
</div> |
|
|
<div class="navfooter"><table width="100%" summary="Navigation footer"> |
|
|
<tr> |
|
|
<td width="40%" align="left"> |
|
|
<a accesskey="p" href="index.html">Prev</a> </td> |
|
|
<td width="20%" align="center"> </td> |
|
|
<td width="40%" align="right"> <a accesskey="n" href="zendx.jquery.html">Next</a> |
|
|
</td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td width="40%" align="left" valign="top">Programmer's Reference Guide </td> |
|
|
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> |
|
|
<td width="40%" align="right" valign="top"> Chapter 2. ZendX_JQuery</td> |
|
|
</tr> |
|
|
</table></div> |
|
|
<div class="revinfo"></div> |
|
|
</body> |
|
|
</html>
|
|
|
|