Hudzilla.org - the homepage of Paul Hudson
Contents > Miscellaneous topics Wish List | Report Bug | About Me ]

16.1     Process control

This is NOT the latest copy of this book; click here for the latest version.

As you should be well aware by now, you can use PHP as a command-line scripting system to automate common tasks. We look at this in more depth later as we explore some of the alternative things you can do with command-line PHP. Right now, however, there are somewhat more mundane things to be thinking about, most notably controlling processes through PHP.

Given that PHP scripts are executed by the PHP parser (php.exe on Windows, and just "php" elsewhere), this parser executable file can only run in one processor on your computer. Naturally this is fine if you only have one processor in your machine, but what if you are on a 2-way or 4-way machine? Or, what if you are on a single-processor box but do not want your command-line script to lock up while executing a long operation?

To solve these problems we need to delve into the realm of process control: the art of spawning child processes and controlling them, and also the ability to take advanced control over the original PHP process. Sadly, the process control functions only work on Unix operating systems right now, which is pretty much everything except Windows - if you are using Windows, you are flat out of luck. Sorry! If you're using Unix, you'll need to configure PHP with the flag --enable-pcntl.

Before you continue, it is important that you understand what a process actually is . Put simply, a process is one running instance of a program, which has its own ID number and its own scheduling from the kernel. By "instance of a program", I mean that you are likely to have only one copy of the PHP executable on your machine, but you can have several running at one time - multiple running instances. Each process has its own unique number assigned to it, and this process ID (PID) is the preferred method for accessing a process.





<< 16 Miscellaneous topics   16.1.1 Taking control of PHP: pcntl_signal() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 07 Sep 2008

<b>test doang</b>

A PHP User - 07 Sep 2008

fsdgsdfgsdfg

A PHP User - 07 Sep 2008

test juga

tes - 07 Sep 2008

perbaiki dulu webnya

Esta bien? - 07 Sep 2008

todo esta bien por aqui?

A PHP User - 07 Sep 2008

test



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is eight plus eight?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow