Reputation: 636
Ok so I've been working on this/with this for a couple of days now. I'm currently working with spatie/browsershot (https://github.com/spatie/browsershot).
Let me explain what I try to do first.
I'm trying to get a screenshot of a webpage (multiple webpages actually). One is a mobile version and the other is a desktop version. Now all this stuff works and doesn't cause any trouble... When I do it one at a time.
I'm also using laravel 5 and their queue system to process multiple webpages at the same time. Here is where my problem starts. When I run about 5 workers to process my queue they all take screenshots which seems no problem at first because the first screenshot they all take always succeeds. But for some reason they just stop at the second screenshot (This doesn't happen when I just do it 1 at a time).
I'm thinking that the executable of phantomjs probably crashes or something due to overload but when I create 2 seperate executables and run them seperatly (One for the mobile SS and one for the desktop SS) I still encounter this problem.
Anyone have an idea or maybe a better solution to get the screenshots I need?
Here's the javascript each process runs
$fileContent= "var page = require('webpage').create();
page.settings.javascriptEnabled = true;
page.viewportSize = { width: " . $this->width . ",height:1000 };
page.open('" . $this->URL . "', function() {
window.setTimeout(function(){
page.render('" . $targetFile . "');
phantom.exit();
}, 5000); // give phantomjs 5 seconds to process all javascript
});";
Also for some reason when I set the height to 1000 it will always take the full height of the page. When I was using $this->width it wouldn't do so.
Upvotes: 4
Views: 1891
Reputation: 86
I also used a phantomjs project in the past, and had a lot of different problems, and our users complained about it, it was quite unstable. We did a lot of restarts of our cron job to successfully achieve screenshots.
And at the moment the phantomjs project is archived. https://github.com/ariya/phantomjs
And as answer to you question about "better solution to get the screenshots I need?" I would suggest to use chrome headless, I use at the moment it in docker container https://hub.docker.com/r/justinribeiro/chrome-headless/
It's fast and stable project, you will need to add additional code using puppeter, but it's not complicated https://developers.google.com/web/tools/puppeteer/
At the moment I don't have any problems with this solution in my application.
Upvotes: 1