PHP Guru - Thread question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qw12er
    Confirmed User
    • Apr 2004
    • 799

    #1

    PHP Guru - Thread question

    Is there a way to do threads in PHP.

    I tried pcntl_fork but it seems to works only on Unix server. (I'm Currently on Linux)

    Thanks
    I have nothing to advertise ... yet.
  • ServerGenius
    Confirmed User
    • Feb 2002
    • 9377

    #2
    it does work on linux....but not with php as an apache module....you have to run
    it as cgi.

    PHP Code:
    
        <?php
        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) {
              sleep(1);
              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-1hahaha8243;);
        $test2 = new testThread (?Thread-2hahaha8243;);
        $test1->start();
        $test2->start();
    
        print ?This is the main process. Press [CTRL-CANC] to terminate.\n?;
        while(true) {sleep(1);}
    
        ?>
    | http://www.sinnerscash.com/ | ICQ: 370820 | Skype: SinnersCash | AdultWhosWho |

    Comment

    Working...