multithreading - php exec() haphazardly working in pthreads -
i use loop exec() file 300 times in pthreads. full 300 exec() calls successful, times few of exec() fail , between 295 or 299 successful executes of file.
the error code exec() comes @ #127, checked file_exists on failures , says "file exists", says "file not executable" on failures. strange because executable other 295 times within loop.
my pthread version 2 months old. confident don't have pthread workers sharing files or writing same spots. scratching head else can do.
class workerthreads extends thread { private $workerid; public function __construct($id) { $this->workerid = $id; } public function run() { $mainfile="/pastlotto_1/".$this->workerid."/preset_pthread.php"; for($x=0; $x<100; $x++) { for($o=0; $o<3; $o++) { $command="php $mainfile"; $finde=exec($command,$output,$return_var); if($return_var !== 0){ echo " file not executed @ worker id ".$this->workerid."\n"; echo $return_var."\n"; if (file_exists($mainfile)) { echo "the file $mainfile exists\n"; } else { echo "the file $mainfile not exist\n"; } if(is_executable($mainfile)) { echo ("file executable\n"); } else { echo ("file not executable\n"); } } else{ echo "file executed successfully"; } } } }//end of run } for($r=0; $r<1; $r++) { $workers = []; // initialize , start threads foreach (range(0,2) $j) { $workers[$j] = new workerthreads($j); $workers[$j]->start(); //echo $i." worker started\n"; } // let threads come foreach (range(0,2) $j) { $workers[$j]->join(); } unset($workers); }
i able solve problem changing code fires pthreads from:
for($r=0; $r<1; $r++) { $workers = []; // initialize , start threads foreach (range(0,2) $j) { $workers[$j] = new workerthreads($j); $workers[$j]->start(); //echo $i." worker started\n"; } // let threads come foreach (range(0,2) $j) { $workers[$j]->join(); } unset($workers); }
to replacement code:
$p = new pool(3); // initialize , start threads for($b=0; $b<3; $b++) { $tasks[$b]= new workerthreads($b); } // add tasks pool queue foreach ($tasks $task) { $p->submit($task); } // shutdown wait current queue completed $p->shutdown();
Comments
Post a Comment