これを行う良い方法を探しています: 私の現在の方法では、php.ini
デフォルトの実行時間と最大メモリ使用量を増やすことを期待して設定を編集した後でも、30-40 を超える深さの検索は許可されていないようです。基本的に、検索の深さがこの量を超えるとすぐに、サーバーがクラッシュします。
これが私のコードです(private function _ParseHtml($html, $depth = nDepth
):
if ($depth === 0)
{
return;
}
@$this->_dom->loadHTML($html);
$this->nodes = $this->_dom->childNodes;
$html = array();
$iterCount = 0;
foreach($this->nodes as $node)
{
if($node->hasChildNodes())
{
$html[$iterCount++] = $node->C14N();
}
$this->_tagCount++;
if ( $this->_config['Debug'] ) _wrapBreak("Tag Count incremented");
}
if( count( $html ) > 0 )
{
$static_depth = $depth - 1;
foreach( $html as $parse )
{
$this->_ParseHtml( $parse, $static_depth );
if ( $this->_config['Debug'] ) _wrapBreak("ParseHtml did return");
}
}
_wrapBreak("<strong>Current Depth</strong> => <strong>{$depth}</strong>");
_Invoke()
スクレイプ機能のメインコードと同様に:
$handle = curl_init($this->_url);
curl_setopt($handle, CURLOPT_BUFFERSIZE, self::BUFSIZE); //BUFSIZE == 50000
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
$this->_data['html'] = curl_exec($handle);
curl_close($handle);
$this->_ParseHtml($this->_data['html']);