Home > Backend Development > PHP Tutorial > A PHP concurrent access example code_PHP tutorial

A PHP concurrent access example code_PHP tutorial

WBOY
Release: 2016-07-21 15:16:45
Original
858 people have browsed it

复制代码 代码如下:

$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);

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325836.htmlTechArticle复制代码 代码如下: ?php $start=$_GET['s']; $end=$_GET['e']; $requests = array(); for ($index = $start; $index $end; $index++) { $url="http://www.essort.com/amfphp/services/...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template