I'm trying to take a screenshot of a website using laravel and headless chrome. Google Chrome was installed successfully on my Centos 7 server. I'm doing test using this shell command and it was successful.
google-chrome --headless --screenshot --window-size=1350,768 --hide-scrollbars https://google.com
In Laravel 6.6.0, I'm using Symfony Process to run the command. Below is the code.
$process = new Process("google-chrome --headless --screenshot --window-size=1350,768 --hide-scrollbars https://google.com");
$process->setTimeout(8000);
$process->setWorkingDirectory(storage_path('app/public/'));
$process->run();
However, it gives below error. I don't know what error it is.
I tried to verify the server permission by replacing with this code. It was successful.
$process = new Process('cat > test2.txt');
$process->setWorkingDirectory(storage_path('app/public'));
$process->run();
Also tried oh plain php with this code
<?php
shell_exec('google-chrome --headless --screenshot --window-size=1350,768 --hide-scrollbars --no-sandbox https://google.com'); //failed
shell_exec('cat > test.txt'); //success
?>
Am I missing something?
Below is Laravel Error
Symfony\Component\Process\Exception\ProcessSignaledException
The process has been signaled with signal "4".
Symfony\Component\Process\Process::wait :426
vendor/symfony/process/Process.php:426
.
$this->callback = $this->buildCallback($callback);
}
do {
$this->checkTimeout();
$running = '\\' === \DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
$this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running);
} while ($running);
while ($this->isRunning()) {
$this->checkTimeout();
usleep(1000);
}
if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
throw new ProcessSignaledException($this);
}
return $this->exitcode;
}