ヘッドレスchromeでスクレイピングを行う処理をlaravelに組み込んでいます。
使っているドライバはfacebookのphp-webdriverです。
以下のようなChromeClientクラスを作り、コンストラクタの中でchromeを起動しています。
<?php namespace App\Lib; use Facebook\WebDriver\Chrome\ChromeDriver; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Exception\WebDriverException; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebElement; use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverExpectedCondition; class ChromeClient { public $driver; public function __construct() { putenv('webdriver.chrome.driver=/usr/local/bin/chromedriver'); $option = new ChromeOptions(); $option->addArguments(['--no-sandbox']); $option->addArguments(['--headless']); $option->addArguments(['--disable-gpu']); $option->addArguments(['--disable-dev-shm-usage']); $option->addArguments(['--disable-extensions']); $option->addArguments(['--no-zygote']); $chrome = DesiredCapabilities::chrome(); $chrome->setCapability(ChromeOptions::CAPABILITY, $option); $this->driver = ChromeDriver::start($chrome); }
webアクセスでコントローラからChromeClientクラスのインスタンスを作る時は問題ありませんでした。
しかし、バッチ処理としてコマンドクラスからChromeClientクラスのインスタンスを生成すると、ChromeDriver::start($chrome)
で落ちてしまいます。
どちらも実行ユーザはapacheです。
[2018-10-11 20:10:06] local.ERROR: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 3.10.0-327.4.5.el7.x86_64 x86_64) {"exception":"[object] (Facebook\WebDriver\Exception\UnknownServerException(code: 0): unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 3.10.0-327.4.5.el7.x86_64 x86_64) at /vagrant/SampleSite/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114)
また、httpdのphp.confに、
SetEnv webdriver.chrome.driver /usr/local/bin/chromedriver
を追加してみましたが、同様のエラーが吐き出されchromeは起動できませんでした。
対処方法をご存知の方、ご教授下さい。
環境
- CentOS7.2
- apache2.4
- Laravel5.5
- php7.2
- php-webdriver2.42

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。