Проект для складирования кода ZF 1.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zend-framework-1x/extras/documentation/manual/extras/en/zendx.console.process.unix....

131 lines
6.3 KiB

<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">&lt;sect1&gt;
<span style="color: red">&lt;title&gt;ZendX_Console_Process_Unix&lt;/title&gt;</span>
<span style="color: red">&lt;sect2&gt;
<span style="color: red">&lt;title&gt;Introduction&lt;/title&gt;</span>
<span style="color: red">&lt;para&gt;
<span style="color: red">&lt;classname&gt;ZendX_Console_Process_Unix&lt;/classname&gt;</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">&lt;code&gt;shmop_*&lt;/code&gt;</span>, <span style="color: red">&lt;code&gt;pcntl_*&lt;/code&gt;</span> and
<span style="color: red">&lt;code&gt;posix_*&lt;/code&gt;</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.
&lt;/para&gt;</span>
&lt;/sect2&gt;</span>
<span style="color: red">&lt;sect2&gt;
<span style="color: red">&lt;title&gt;Basic usage of ZendX_Console_Process_Unix&lt;/title&gt;</span>
<span style="color: red">&lt;para&gt;
<span style="color: red">&lt;classname&gt;ZendX_Console_Process_Unix&lt;/classname&gt;</span> is an abstract class, which
requires the user to extend it. It has a single abstract method
called <span style="color: red">&lt;methodname&gt;_run()&lt;/methodname&gt;</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.
&lt;/para&gt;</span>
<span style="color: red">&lt;para&gt;
The <span style="color: red">&lt;methodname&gt;_run()&lt;/methodname&gt;</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.
&lt;/para&gt;</span>
<span style="color: red">&lt;para&gt;
<span style="color: red">&lt;methodname&gt;setVariable()&lt;/methodname&gt;</span> and <span style="color: red">&lt;methodname&gt;getVariable()&lt;/methodname&gt;</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">&lt;methodname&gt;_setAlive()&lt;/methodname&gt;</span> in a frequent interval, so that the parent
process can check the last alive time via <span style="color: red">&lt;methodname&gt;getLastAlive()&lt;/methodname&gt;</span>.
To get the PID of the child process, the parent can call
<span style="color: red">&lt;methodname&gt;getPid()&lt;/methodname&gt;</span>.
&lt;/para&gt;</span>
<span style="color: red">&lt;example&gt;
<span style="color: red">&lt;title&gt;Basic example for processing&lt;/title&gt;</span>
<span style="color: red">&lt;para&gt;
This example illustrates a basic child process
&lt;/para&gt;</span>
<span style="color: red">&lt;programlisting&gt;
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() || $process2-&gt;isRunning()) {
sleep(1);
}
echo 'All processes completed';
&lt;/programlisting&gt;</span>
<span style="color: red">&lt;para&gt;
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).
&lt;/para&gt;</span>
&lt;/example&gt;</span>
&lt;/sect2&gt;</span>
&lt;/sect1&gt;</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>