cacert-testmgr/external/ZendFramework-1.9.5/extras/documentation/manual/extras/en/zendx.console.process.unix.html
Markus Warg 8398c9048d initially import ZendFramework-1.9.5 into repository
code was modified slightly, so the code differs from the original downloadable 1.9.5 version
2010-03-31 10:12:32 +02:00

141 lines
6.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 1. ZendX_Console_Process_Unix</title>
<link rel="stylesheet" href="dbstyle.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" 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">
<link rel="section" href="zendx.console.process.unix.html#zendx.console.process.unix.overview" title="1.1. ZendX_Console_Process_Unix">
</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" lang="en">
<div class="titlepage"><div><div><h2 class="title">
<a name="zendx.console.process.unix"></a>Chapter 1. ZendX_Console_Process_Unix</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="sect1"><a href="zendx.console.process.unix.html#zendx.console.process.unix.overview">1.1. ZendX_Console_Process_Unix</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zendx.console.process.unix.html#zendx.console.process.unix.introduction">1.1.1. Introduction</a></span></dt>
<dt><span class="sect2"><a href="zendx.console.process.unix.html#zendx.console.process.unix.basic">1.1.2. Basic usage of ZendX_Console_Process_Unix</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="zendx.console.process.unix.overview"></a>1.1. ZendX_Console_Process_Unix</h2></div></div></div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zendx.console.process.unix.introduction"></a>1.1.1. Introduction</h3></div></div></div>
<p>
<code class="code">ZendX_Console_Process_Unix</code> 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 <code class="code">shmop_*</code>, <code class="code">pcntl_*</code> and
<code class="code">posix_*</code> 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.
</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zendx.console.process.unix.basic"></a>1.1.2. Basic usage of ZendX_Console_Process_Unix</h3></div></div></div>
<p>
<code class="code">ZendX_Console_Process_Unix</code> is an abstract class, which
requires the user to extend it. It has a single abstract method
called <code class="code">_run()</code> 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.
</p>
<p>
The <code class="code">_run()</code> 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.
</p>
<p>
<code class="code">setVariable()</code> and <code class="code">getVariable()</code> can be
used from both the parent- and the child process to share variables.
To observe the alive status, the child process should call
<code class="code">_setAlive()</code> in a frequent interval, so that the parent
process can check the last alive time via <code class="code">getLastAlive()</code>.
To get the PID of the child process, the parent can call
<code class="code">getPid()</code>.
</p>
<div class="example">
<a name="zendx.console.process.unix.example"></a><p class="title"><b>Example 1.1. Basic example for processing</b></p>
<div class="example-contents">
<p>
This example illustrates a basic child process
</p>
<pre class="programlisting">
class MyProcess extends ZendX_Console_Process_Unix
{
protected function _run()
{
for ($i = 0; $i &lt; 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-&gt;start();
$process2 = new MyProcess();
$process2-&gt;start();
while ($process1-&gt;isRunning() &amp;&amp; $process2-&gt;isRunning()) {
sleep(1);
}
echo 'All processes completed';
</pre>
<p>
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).
</p>
</div>
</div>
<br class="example-break">
</div>
</div>
</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>