PHPでお手軽マルチタスクってできないの?

PHPでお手軽マルチタスクってできないの? – ぎじゅっやさん

cURLにはマルチタスク処理用のcurl_multiというものがあるんですね。
マニュアルにはこうあります。

[php]
// cURL リソースを作成します
$ch1 = curl_init();
$ch2 = curl_init();

// URL およびその他適切なオプションを設定します。
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

// マルチ cURL ハンドルを作成します
$mh = curl_multi_init();

// ふたつのハンドルを追加します
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$running=null;
// ハンドルを実行します
do {
curl_multi_exec($mh,$running);
} while ($running > 0);

// ハンドルを閉じます
curl_multi_remove_handle($ch1);
curl_multi_remove_handle($ch2);
curl_multi_close($mh);

?>
[/php]

これは素敵ですね。マルチタスク的なものを自前で作ろうと思っていたのですが、とりあえずコレで色々とテストしてみたいと思います。

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">