problem description
can be implemented independently: multithreaded capture and dynamic rendering pages
but if you want to merge the two, you don"t know how to do it.
you help.
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
/ * *
*
*/
public function multi(){
$ql = QueryList::getInstance();
$ql->use(CurlMulti::class);
$ql->use(CurlMulti::class,"curlMulti");
//
$ql->rules([
"city" => [
"-sharpspeedlist [name=city]",
"text"
],
"time" => [
"-sharpspeedlist [name=conntime]",
"text"
]
])->curlMulti([
"http://tool.chinaz.com/speedtest/baidu.com/",
"http://tool.chinaz.com/speedtest/163.com/",
])->success(function (QueryList $ql,CurlMulti $curl,$r){
/** **/
echo "Current url:{$r["info"]["url"]} \r\n";
$data = $ql->query()->getData();
print_r($data->all());
})->start([
//
"maxThread" => 10,
//
"maxTry" => 3
]);
}
/ * *
- use PhantomJS to capture JavaScript dynamically rendered pages
* /
public function phantomjs () {
set_time_limit(0);
$domain = "www.baidu.com";
$ql = QueryList::getInstance();
// PhantomJS
$ql->use(PhantomJs::class, "/www/wwwroot/phantomjs/bin/phantomjs");
// or Custom function name
$ql->use(PhantomJs::class, "/www/wwwroot/phantomjs/bin/phantomjs", "browser");
$data = $ql->browser(function (\JonnyW\PhantomJs\Http\RequestInterface $r) use ($domain) {
$r->setMethod("GET");
$r->setUrl("http://tool.chinaz.com/speedtest/" . $domain);
$r->setTimeout(1000 * 40); // 60 seconds
$r->setDelay(25); // 3 seconds
return $r;
})
->rules([
"city" => [
"-sharpspeedlist [name=city]",
"text"
],
"time" => [
"-sharpspeedlist [name=conntime]",
"text"
]
])
->query()
->getData();
echo ($data->all());
exit();
}