PHP: Process Control Functions

I had quite forgotten that PHP can fork a process just like in C! This might be a useful thing to know for doing background tasks, but to be honest the extra complexity required will probably put me off doing it. That’s where this Thread class comes in handy..

include ("threadClass.php");

class testThread extends Thread {

  function testThread($name) {
    $this->Thread($name); // calls the parent constructor and assign its name

  function run() {
    while(true) {
      print time() ."-" . $this->getName() . " said ok...\n"; // every second we're going to print this line...
// Main program. Bring up two instances of the same class (testThread).
// They runs concurrently. It's a multi-thread app with a few lines of code!!!

$test1 = new testThread ("Thread-1");
$test2 = new testThread ("Thread-2");

print "This is the main process. Press [CTRL-CANC] to terminate.\n";
while(true) {sleep(1);}


One thought on “PHP: Process Control Functions

  1. I posted about the same topic a couple of days ago. It’s a great class. As soon as I get over some of the routing projects I got goin’ on, I plan on messing with it a little.


Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.