我无法在多卷曲场景中找到有关特定卷曲句柄的更多信息。这是代码。
$job_count = 5;
while ( $eachPr = $prList->fetch () ) {
for ( $job_number = 1 ;
$job_number <= $job_count ;
$job_number ++ , $index ++ ) {
$url = $this->getURL ( $eachPr[ "name" ] ,
$eachPr[ "category" ] ) ;
$this->log ( $url ) ;
$curl_handle = curl_init () ;
curl_setopt ( $curl_handle ,
CURLOPT_USERAGENT ,
$userAgent ) ;
curl_setopt ( $curl_handle ,
CURLOPT_URL ,
$url ) ;
curl_setopt ( $curl_handle ,
CURLOPT_FAILONERROR ,
TRUE ) ;
curl_setopt ( $curl_handle ,
CURLOPT_FOLLOWLOCATION ,
TRUE ) ;
curl_setopt ( $curl_handle ,
CURLOPT_AUTOREFERER ,
TRUE ) ;
curl_setopt ( $curl_handle ,
CURLOPT_RETURNTRANSFER ,
TRUE ) ;
curl_setopt ( $curl_handle ,
CURLOPT_COOKIE ,
$cookie ) ;
var_dump($curl_handle);
/* add a request to the multiple handle */
curl_multi_add_handle ( $multi_handler ,
$curl_handle ) ;
$eachPr = $prList->fetch () ;
}
do {
while ( ($execrun = curl_multi_exec ( $multi_handler ,
$running )) == CURLM_CALL_MULTI_PERFORM ) ;
if ( $execrun != CURLM_OK ) {
break ;
}
/* a request was just completed -- find out which one */
while ( $done = curl_multi_info_read ( $multi_handler ) ) {
/* get the info and content returned on the request */
$info = curl_getinfo ( $done[ 'handle' ] ) ;
$output = curl_multi_getcontent ( $done[ 'handle' ] ) ;
var_dump($info);
/* send the return values to the thread waiting to process the data .
$this->work_pool[] = $this->submit ( new PrStacker ( $eachPr[ "name" ] ,
$eachPr[ "id" ] ,
$output ) ) ;
$this->work_pool[ count ( $this->work_pool ) - 1 ]->wait () ;
/* remove the curl handle that just completed */
curl_multi_remove_handle ( $multi_handler ,
$done[ 'handle' ] ) ;
}
/* Block for data in / output; error handling is done by curl_multi_exec */
if ( $running ) {
curl_multi_select ( $multi_handler ,
30 ) ;
}
} while ( $running ) ;
/* write the current index to the file */
file_put_contents ( $symbols_index_file ,
$index ) ;
$sleep_interval = rand ( 5 ,
10 ) ;
$this->log ( " Sleeping Now For " . $sleep_interval . " seconds" ) ;
sleep ( $sleep_interval ) ;
$index ++ ;
}
curl_multi_close ( $multi_handler ) ;
所以在这里我使用循环遍历 11K 产品列表while ( $eachPr = $prList->fetch () )
。然后一次使用 5 个产品,我初始化卷曲手柄,并将其添加到卷曲多手柄中。
句柄在 do while 循环中执行。选择刚刚使用完成的请求后,出现了麻烦$done = curl_multi_info_read ( $multi_handler )
。
每个响应都会传递到处理其他任务的另一个线程。每个线程都需要产品名称、产品 ID 和原始 html 响应。
这是每个堆栈器的初始化方式
$this->work_pool[] = $this->submit ( new PrStacker ( $eachPr[ "name" ] ,
$eachPr[ "id" ] ,
$output ) ) ;
但是在每个卷曲请求完成后,我找不到发送与已完成的请求相对应的正确产品名称和 ID 的方法。当在上面的代码中我将名称、id 和输出传递到 PrStacker 线程时,我意识到它不是与已完成的请求相对应的正确产品。它是传递给线程的不同且错误的产品。
那么,有什么方法可以在执行之前将产品名称和 id 与每个curl 句柄/请求一起包含在内,以便程序可以识别哪个响应对应于哪个产品。我希望我的解释能够被理解。
请告诉我是否有任何方法可以做到这一点。