Laravel hotrush/Webshotter持续报页面加载超时错误求助
Hey there, let's work through why you're hitting that "page load timeout" error while trying to capture baidu.com using webshot. I’ve run into similar headaches before, so here are some practical angles to check:
Anti-scraping measures might be blocking your request
Sites like Baidu often flag automated tools like webshot and throttle or block their access. A quick fix is to mimic a real browser’s user agent to bypass basic detection. Add this line to your code:->setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36')Timeout settings might need a tweak
Even with a 45-second timeout, dynamic pages like Baidu can take longer to fully render all their content. Try bumping the main timeout to 60 or 90 seconds first. You can also temporarily disablewaitForImages()to see if the page loads without waiting for every asset—this will help rule out slow-loading images causing the hang.Check server connectivity and proxy setup
If your server is behind a proxy, webshot might not be configured to use it, leading to slow or failed connections. Runcurl https://baidu.comfrom your server to confirm it can reach the site quickly. If you need a proxy, look into webshot’s proxy configuration options to set that up.Update webshot to the latest version
Older versions of the library might have bugs related to page loading timeouts. Updating to the most recent release could resolve the issue outright.
Here’s a modified version of your code with some of these adjustments:
$jpg = $webshot ->setUrl('https://baidu.com/') ->setWidth(1200) ->setHeight(800) ->setTimeout(60) // Extended main timeout ->setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36') ->setFullPage(false) ->waitForImages() ->setImagesLoadingTimeout(180) ->saveToPng('baidu_full', 'myimages/');
If none of these work, enable webshot’s debug mode to get detailed logs—this will show you exactly which resource is hanging and causing the timeout.
内容的提问来源于stack exchange,提问作者fengnan

