<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux, Programming, Telephony, Asterisk, Apache, Tips &#38; Tricks &#187; background process</title>
	<atom:link href="http://shahidz.com/tag/background-process/feed/" rel="self" type="application/rss+xml" />
	<link>http://shahidz.com</link>
	<description>Passionate About Technology</description>
	<lastBuildDate>Sun, 10 Jan 2010 17:38:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Background Process or a Deamon Process using PHP</title>
		<link>http://shahidz.com/background-process-or-a-deamon-process-using-php/</link>
		<comments>http://shahidz.com/background-process-or-a-deamon-process-using-php/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 06:33:18 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[background process]]></category>
		<category><![CDATA[deamon]]></category>
		<category><![CDATA[pcntl]]></category>

		<guid isPermaLink="false">http://shahidz.com/?p=16</guid>
		<description><![CDATA[ Process Control Functions (PCNTL) 
 Introduction 
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.
 Requirements [...]]]></description>
			<content:encoded><![CDATA[<p class="entry"><strong><u> Process Control Functions (PCNTL) </u></strong></p>
<p><em><u> Introduction </u></em></p>
<p>Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.</p>
<p><em><u> Requirements </u></em></p>
<p>No external libraries are needed to build this extension.</p>
<p><em><u> Installation </u></em></p>
<p>Process Control support in PHP is not enabled by default. You have to compile the CGI or CLI version of PHP with –enable-pcntl configuration option when compiling PHP to enable Process Control support.</p>
<p><strong> Examples </strong></p>
<p>This example forks off a daemon process with a signal handler.</p>
<p>#!/usr/local/bin/php -q //Include the file php</p>
<p>&lt;&#8217;?php&#8217;<br />
declare(ticks=1);<br />
$cmd = ‘php’;<br />
$file = array(’parse.php’);<br />
$pid = pcntl_fork();<br />
if ($pid == -1)<br />
{<br />
die(”could not fork”);<br />
}<br />
else if ($pid)<br />
{<br />
echo “parent”;<br />
exit(); // we are the parent<br />
}<br />
else<br />
{<br />
echo “Child”;<br />
exit(); // we are the child<br />
}<br />
// detatch from the controlling terminal<br />
if (posix_setsid() == -1)<br />
{<br />
echo $pid;<br />
echo “\n”;<br />
die(”could not detach from terminal\n”);<br />
}</p>
<p>// setup signal handlers<br />
pcntl_signal(SIGTERM, “sig_handler”);<br />
pcntl_signal(SIGHUP, “sig_handler”);</p>
<p>// loop forever performing tasks<br />
while (1)<br />
{<br />
// do something interesting here<br />
pcntl_exec(’php’,&#8217;file.php’); // executes ‘file.php’ in the back ground.<br />
echo “”;<br />
//              exit;</p>
<p>}<br />
function sig_handler($signo)<br />
{</p>
<p>switch ($signo)<br />
{<br />
case SIGTERM:<br />
// handle shutdown tasks<br />
echo “\nShutdown”;<br />
exit;<br />
break;<br />
case SIGHUP:<br />
// handle restart tasks<br />
echo “restart”;<br />
break;<br />
default:<br />
// handle all other signals<br />
}</p>
<p>}</p>
<p>‘?&gt;’</p>
<p>For more details <a href="http://www.php.net/manual/en/ref.pcntl.php"> Click here </a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fbackground-process-or-a-deamon-process-using-php%2F&amp;linkname=Background%20Process%20or%20a%20Deamon%20Process%20using%20PHP"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/background-process-or-a-deamon-process-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
