I want to use some threads to do my computations and my web service work faster. don't go deep on calculations, it works correctly. However, my problem is without using this thread it was taking something around 55 sec although now it's something around 55 sec again.
So I'm wondering am I using it in a right way? Is this correct form of using pthreads?
My php version : 5.5.12
class workerThread extends Thread {
public function __construct($eng,$year,$capacity){
$this->eng = $eng;
$this->year = $year;
$this->capacity = $capacity;
}
public function run(){
$counter=0;
$paye1=0;
$paye2=0;
$paye3=0;
foreach($this->eng as $engs){
$data=filter_engs($engs['id'],$this->year,$this->capacity);
if(isset($data['state'])){
if($engs['checkLevel']=='one'){
$paye1++;
$list[$counter]['avgCap']='2304';
$list[$counter]['avg']=ceil(($data['cheked']/2304)*100);
$list[$counter]['fullavg']=ceil(($data['cheked']/$data['allWork'])*100);
}else if($engs['checkLevel']=='two'){
$paye2++;
$list[$counter]['avgCap']='1728';
$list[$counter]['avg']=ceil(($data['cheked']/1728)*100);
$list[$counter]['fullavg']=ceil(($data['cheked']/$data['allWork'])*100);
}else if($engs['checkLevel']=='three'){
$paye3++;
$list[$counter]['avgCap']='1152';
$list[$counter]['avg']=ceil(($data['cheked']/1152)*100);
$list[$counter]['fullavg']=ceil(($data['cheked']/$data['allWork'])*100);
}
$list[$counter]['allWork']=$data['allWork'];
$list[$counter]['wCap']=$data['wCap'];
$list[$counter]['cheked']=$data['cheked'];
$list[$counter]['design']=$data['wCap']-$data['cheked'];
$list[$counter]['countCheked']=$data['countCheked'];
$list[$counter]+=$engs;
$counter++;
}
}
return $list;
}
}
And this is how I use it:
$worker=new workerThread($eng,$year,$cap);
$list=$worker->run();
$worker->kill();
//and doing some stuff with $list array