https://github.com/krakjoe/pthreads
<?php
class Possibilities extends Thread {
public function __construct($url){
$this->url = $url;
}
public function run(){
/*
* Or use curl, this is quicker to make an example ...
*/
return file_get_contents($this->url);
}
}
$threads = array();
$urls = get_my_urls_from_somewhere();
foreach($urls as $index => $url){
$threads[$index]=new Possibilities($url);
$threads[$index]->start();
}
foreach($threads as $index => $thread){
if(($response = $threads[$index]->join())){
/** good, got a response */
} else { /** we do not care **/ }
}
?>
我的猜測是,您使用的是捲曲的多,因爲它是對代碼向用戶發送電子郵件的併發執行的唯一選擇......如果是這樣的話,我不建議你使用類似上面的代碼,我建議你直接調用mail(),因爲這將會更快,更高效。
但是現在你知道了,你可以在PHP中線程..享受:)