Interestingly php multithreading pthreads extension

Recently, a small windwos project uses a php multithreading, no alternative can only use pthreads, met some interesting pit pits, recorded hope to help a friend read.

1, can only be created in the main thread child thread

  I originally wanted to own a class compiled by zephir extension, this part of the code just inherited a thread, call -> start () an error.

2, two threads variable names, can only be executed one by one (blocked).

class cct extends Thread {
                private $c;
                
                function __construct($c){
                    $this->c=$c;
                }
                public function run() {
                    while($i++<10){ usleep(100000); echo $this->c; } } } function mkt($c){ $t = new cct($c); $t->start(); } $a = new cct("a"); $a->start(); $a = new cct("b"); $a->start(); mkt("c"); mkt("d");

Output: aaaaaaaaaabcbcbcbcbcbcbcbcbcbcdddddddddd

 

Guess you like

Origin www.cnblogs.com/spooking/p/11499128.html