1

私はcurl_multiを使用して、これに似たローリングcurlスクリプトでメールを送信していますが、10秒のcurlopt_timeoutと20秒のcurlopt_connecttimeoutを追加しました http://www.onlineaspect.com/2009/01/26/how- to-use-curl_multi-without-blocking /

テスト中に、timeout_msとconnecttimeout_msをそれぞれ使用して、タイムアウトを1msに減らしました。これは、タイムアウトがどのように処理されるかを確認するためです。ただし、タイムアウトにより、カールプロセス全体が強制終了されます。1つがタイムアウトしても、他のスレッドを続行する方法はありますか?ありがとう。

-ディーヴォ

4

1 に答える 1

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 **/ }
}
?>

私の推測では、電子メールを送信するコードを同時に実行するための唯一のオプションであるため、curl multi を使用していると思います。この場合、上記のコードのようなものを使用することはお勧めしません。これははるかに高速で効率的であるため、直接 mail() を呼び出します。

しかし、今では、PHP でスレッド化することができます..お楽しみください :)

于 2012-09-13T19:13:30.903 に答える