2012-09-11 46 views
1

我使用curl_multi發出電子郵件,出類似這樣的滾動捲曲劇本,但我加10秒的curlopt_timeout爲20秒 http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/curl_multi_exec殺死整個過程時,有保險業監督一個超時

一個curlopt_connecttimeout

測試它時,我分別使用timeout_ms和connecttimeout_ms將超時減少到1ms,以查看它是如何處理超時的。但超時會殺死整個捲曲過程。有沒有辦法繼續與其他線程,即使一次? 謝謝。

-devo

回答

0

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中線程..享受:)