我使用OctoberCMS并将此代码放在页面的后端,该页面从特定页面获取所有链接
$html = file_get_contents("http://somepage.com/");
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_clear_errors();
$xpath = new DOMXPath($doc);
foreach ($doc->getElementsByTagName('a') as $link){
if (parse_url($link->getAttribute('href'), PHP_URL_SCHEME) === 'https') {
$links[] = array('url' => $link->getAttribute('href'));
}
$haystack = $link->getAttribute('href');
$needle = "ht";
if( strpos( $haystack, $needle ) !== false ) {
echo $haystack."<br>";
}
else
{
continue;
}
}
但每当我尝试加载只有2个链接的页面本身时,我就会得到常量循环,页面根本不会加载,导致服务器向我返回SQLSTATE[HY000] [1203] User ahmcho_ahmad already has more than 'max_user_connections' active connections
错误。我不明白为什么会收到这个错误?