本文整理匯總了PHP中Crawler::execHandle方法的典型用法代碼示例。如果您正苦於以下問題:PHP Crawler::execHandle方法的具體用法?PHP Crawler::execHandle怎麽用?PHP Crawler::execHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crawler
的用法示例。
在下文中一共展示了Crawler::execHandle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: foreach
foreach ($curlList as $outfile => $curlEl) {
// exec("mkdir \"".dirname($outfile)."\\\"");
file_put_contents($outfile, curl_multi_getcontent($curlEl));
curl_multi_remove_handle($curlHandle, $curlEl);
}
curl_multi_close($curlHandle);
$n = 0;
$curlList = array();
}
}
echo "\n";
flush();
}
// the last call
if ($curlList) {
Crawler::execHandle($curlHandle);
foreach ($curlList as $outfile => $curlEl) {
// exec("mkdir \"".dirname($outfile)."\\\"");
file_put_contents($outfile, curl_multi_getcontent($curlEl));
curl_multi_remove_handle($curlHandle, $curlEl);
}
curl_multi_close($curlHandle);
}
}
break;
case 'phase4':
// folder yg -original$ dan -reprint$ digabung jdai satu
// filenamenya diprefix ^original- dan ^reprint-
$dirname = 'Carl Barks';
$subdirs = scandir($dirname);
$n = count($subdirs);
示例2: multiProcess
/**
* Mendownload $size buah link sekaligus, lalu diproses oleh fungsi $function
* @param integer $size jumlah thread yg diinginkan
* @param array $pages_url array of full url
* @param string $function nama fungsi yang dipanggil untuk memproses 1 halaman,
* fungsinya punya 2 parameter (resource $fil, string $url)
* @param array $params parameter tambahan ke fungsi
*/
public static function multiProcess($size, $pages_url, $function, $params = false)
{
$n = 0;
$curlHandle = null;
$curlList = array();
foreach ($pages_url as $aurl) {
if ($n == 0) {
$curlHandle = curl_multi_init();
}
$curlList[$aurl] = Crawler::addHandle($curlHandle, $aurl);
$n++;
if ($n >= $size) {
Crawler::execHandle($curlHandle);
foreach ($curlList as $theurl => $curlEl) {
$html = curl_multi_getcontent($curlEl);
// Ada kemungkinan gagal retrieve
if (trim($html)) {
$fil = tmpfile();
fwrite($fil, $html);
} else {
$fil = $theurl;
}
if ($params) {
call_user_func_array($function, array_merge(array($fil, $theurl), $params));
} else {
$function($fil, $theurl);
}
curl_multi_remove_handle($curlHandle, $curlEl);
}
curl_multi_close($curlHandle);
$n = 0;
$curlList = array();
}
}
if ($curlList) {
Crawler::execHandle($curlHandle);
foreach ($curlList as $theurl => $curlEl) {
$html = curl_multi_getcontent($curlEl);
// Ada kemungkinan gagal retrieve
if (trim($html)) {
$fil = tmpfile();
fwrite($fil, $html);
} else {
$fil = $theurl;
}
if ($params) {
call_user_func_array($function, array_merge(array($fil, $theurl), $params));
} else {
$function($fil, $theurl);
}
curl_multi_remove_handle($curlHandle, $curlEl);
}
curl_multi_close($curlHandle);
}
}