2017-07-25 23 views
0

私はforループを使ってpthreadsでファイルを300回exec()します。場合によっては300回のexec()呼び出しが成功することもありますが、ほとんどの場合exec()のいくつかが失敗し、ファイルを295回または299回実行します。php exec()はうんざりpthreadsで働いています

exec()のエラーコードはいつも#127に戻ってきます。 ファイルの存在をチェックしたところ、常に「ファイルは存在します」と表示されますが、失敗した場合は「ファイルは実行できません」と表示されます。これはループ内で他の295回実行可能であったので奇妙です。

私のpthreadバージョンはわずか2ヶ月です。ファイルを共有したり、同じ場所に書き込んだりする人がいないと私は確信しています。他に何ができるかで私の頭を掻きます。

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 at worker id ".$this->workerId."\n"; 
    echo $return_var."\n"; 

    if (file_exists($mainfile)) { 
    echo "The file $mainfile exists\n"; 
} else { 
    echo "The file $mainfile does not exist\n"; 
} 
    if(is_executable($mainfile)) 
    { 
    echo ("file is executable\n"); 
    } 
else 
    { 
    echo ("file is not executable\n"); 
    } 
} 
else{ 
    echo "File executed Successfully"; 
} 
    } 
} 
     }//END OF RUN 

} 

for($r=0; $r<1; $r++) 
{ 
$workers = []; 

// Initialize and start the threads 
foreach (range(0,2) as $j) { 

    $workers[$j] = new WorkerThreads($j); 
    $workers[$j]->start(); 


    //echo $i." worker started\n"; 
} 

// Let the threads come back 
foreach (range(0,2) as $j) { 
    $workers[$j]->join(); 

} 
unset($workers); 

} 

答えて

0

私はからpthreadsをアップ発射コードを変更することで問題を解決することができました:交換用コードに

for($r=0; $r<1; $r++) 
{ 
$workers = []; 

// Initialize and start the threads 
foreach (range(0,2) as $j) { 

    $workers[$j] = new WorkerThreads($j); 
    $workers[$j]->start(); 


    //echo $i." worker started\n"; 
} 

// Let the threads come back 
foreach (range(0,2) as $j) { 
    $workers[$j]->join(); 

} 
unset($workers); 

} 

$p = new Pool(3); 



// Initialize and start the threads 
for($b=0; $b<3; $b++) { 
     $tasks[$b]= new WorkerThreads($b); 


    } 


    // Add tasks to pool queue 
    foreach ($tasks as $task) { 
     $p->submit($task); 
    } 

    // shutdown will wait for current queue to be completed 
    $p->shutdown(); 
関連する問題