php pthreads won't launch on xampp 7.0.2

后端 未结 2 1675
醉酒成梦
醉酒成梦 2021-01-29 02:34

I have installed fresh xampp (7.0.2 atm). I\'ve created php-cli.ini, added pthread extension there and set memory limit to 3 gb. But when I\'am trying to launch thread script I

2条回答
  •  一个人的身影
    2021-01-29 02:51

    My PHP version: 7.2.6 x82 And pthreads: php_pthreads-3.1.6-7.2-ts-vc15-x86 I created 25 threads, when created 21th thread then occurred same error. I thought that it only can create 20 threads. So I edited my code and that error does not occur My code:

    class ReadAllFile extends Thread {
    
        public $folder;
    
        public function __construct($folder) {
            $this->folder = $folder;
        }
    
        public function run() {
            //code process
        }
    
    }
    
    $dir = "F:/sbd/sbdstore/20180606/";
    $subFolders = scandir ( $dir );
    
    $stack = array();
    
    foreach ( $subFolders as $folder ) {
    
        if ($folder != '.' && $folder != '..') {
    
            $stack[] = new ReadAllFile ( $dir.$folder );
        }
    
    
    }
    
    $maxNumberOfThread = 20;
    $numberOfRunning = 0;
    $numberOfStack = count($stack);
    $elementIsStarted = array();
    $allElementIsProcess = false;
    
    while(count($stack)){
    
        if($numberOfRunning <= $maxNumberOfThread && !$allElementIsProcess){
    
            for($i=0;$i<$numberOfStack;$i++){
    
                if(!in_array($i,$elementIsStarted)){
    
                    $numberOfRunning++;
                    $elementIsStarted[] = $i;
                    $stack[$i]->start();
    
                    if($i == $numberOfStack - 1){
    
                        $allElementIsProcess = true;
    
                    }
    
                    $i = $numberOfStack + 1;
    
                }
    
            }
    
        }else{
    
            foreach($elementIsStarted AS $element){
    
                if(isset($stack[$element]) && $stack[$element]->isRunning() !== true){
    
                    unset($stack[$element]);
                    $numberOfRunning--;
    
                }
    
            }
    
        }
    
    } 
    

    Hope this help. Sorry about my English.

    P/s: If I use PHP version: 7.2.6 x64 and php_pthreads-3.1.6-7.2-ts-vc15-x64 then it does not occur this error. I think x64 allocation more memory.

提交回复
热议问题