php模拟并发memcache高并发

转:http://www.jb51.net/article/31213.htm

http://wenku.baidu.com/link?url=KhwAHMpUqJ0Zh-Wb_JdwZXzFcYuDdr8ZtQbT1LmT8EO_wnU5czy6trmDctHoz2NjfIvW4dxaZoQvjuqCw3QZ_AanxBzF4dNNEv4auxsg3b7

php其实也可以执行多任务或并发访问,下面就是网上找来的一个关于PHP并发访问的例子
<?php
$start=$_GET['s'];
$end=$_GET['e'];
$requests = array();
for ($index = $start; $index < $end; $index++) {
$url="http://www.essort.com/amfphp/services/curl/loadTest.php?uid=$index";
$requests[]=$url;
}
$main = curl_multi_init();
$results = array();
$errors = array();
$info = array();
$count = count($requests);
for($i = 0; $i < $count; $i++) {
$handles[$i] = curl_init($requests[$i]);
var_dump($requests[$i]);
curl_setopt($handles[$i], CURLOPT_URL, $requests[$i]);
curl_setopt($handles[$i], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
} while($running > 0);
for($i = 0; $i < $count; $i++)
{
$results[] = curl_multi_getcontent($handles[$i]);
$errors[] = curl_error($handles[$i]);
$info[] = curl_getinfo($handles[$i]);
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
var_dump($results);
var_dump($errors);
var_dump($info);

?>

    A+
发布日期:2014年09月23日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: