I have a controller method that takes a long time (40 minutes) to complete. the method retrieve 3500 domain name and for each one it should search registrar name, expire that and also check if http server is running or not. This is the reason it's taking so long;
this is my code, it works, but slow :
public function sync_domains(){
// get the domain name list
$list = $this->Domain->find('all');
// search for registrar name, expire date and web server status (up|down)
foreach ($list as $key => $record) {
$hostname = $record['Domain']['domain_name'];
$domain = array();
// get registrar name and expire date
$whois = $this->whois($hostname);
$domain['Domain']['registrar'] = $whois['registrar'];
$domain['Domain']['expire_date'] = $whois['expire_date'];
// get the web status
$domain['Domain']['web_status'] = $this->httpStatus($hostname);
$newData[] = $domain;
}
// save new data
if(!empty($newData)){
if($this->DomainStatus->saveMany($newData)){
$this->Flash->success(__(count($newData).' Domains has been added successfully'), array('key' => 'success'));
}else{
$this->Flash->danger(__('An Error occured while saving data'), array('key' => 'danger'));
}
}
// redirect to referer
return $this->redirect($this->referer());
}
is there any way to use multithreading to launch whois and httpstatus functions for multiple domain name at the same time ?
thanks,