wp cliで一括処理するととても便利なのですが、処理が途中で止まってしまうことがありました。
何度かやっても同じようなところで止まってしまい、wp cliのファイルからエラーを吐いているので、原因はよくわからず。
wp cliアボートの原因はプラグイン?
よくよく見てみて見るとプラグインのファイル名があったので、XML sitemapのプラグインがギブアップしている可能性が高いと考えました。
記事の更新を連続して行っている処理だったので、更新の通知の影響でXML sitemapプラグインが動いているのかもしれません。
PHP Warning: include(phar:///home/xxxx/bin/wp/vendor/composer/../rmccue/requests/library/Requests/Exception.php): failed to open stream: phar error: Cannot open phar archive "/home/xxxx/bin/wp" for reading in phar:///home/xxxx/bin/wp/vendor/composer/ClassLoader.php on line 571 Warning: include(phar:///home/xxxx/bin/wp/vendor/composer/../rmccue/requests/library/Requests/Exception.php): failed to open stream: phar error: Cannot open phar archive "/home/xxxx/bin/wp" for reading in phar:///home/xxxx/bin/wp/vendor/composer/ClassLoader.php on line 571 PHP Warning: include(): Failed opening 'phar:///home/xxxx/bin/wp/vendor/composer/../rmccue/requests/library/Requests/Exception.php' for inclusion (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in phar:///home/xxxx/bin/wp/vendor/composer/ClassLoader.php on line 571 Warning: include(): Failed opening 'phar:///home/xxxx/bin/wp/vendor/composer/../rmccue/requests/library/Requests/Exception.php' for inclusion (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in phar:///home/xxxx/bin/wp/vendor/composer/ClassLoader.php on line 571 PHP Fatal error: Uncaught Error: Class 'Requests_Exception' not found in phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:443 Stack trace: #0 phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php(179): Requests_Transport_cURL->process_response('', Array) #1 phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests.php(381): Requests_Transport_cURL->request('https://www.bin...', Array, NULL, Array) #2 /home/xxxx/public_html/yyyy/wp-includes/class-wp-http.php(395): Requests::request('https://www.bin...', Array, NULL, 'GET', Array) #3 /home/xxxx/public_html/yyyy/wp-includes/http.php(145): WP_Http->request('https://www.bin...', Array) #4 /home/xxxx/public_html/yyyy/wp-content/plugins/xml-sitemap-feed/models/functions.shared.php(125): wp_remote_request('https://www.bin...') #5 /home/xxxx/public_html/yyyy/wp-content/plugins/xml-sitemap-feed/controller in phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php on line 443 Fatal error: Uncaught Error: Class 'Requests_Exception' not found in phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:443 Stack trace: #0 phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php(179): Requests_Transport_cURL->process_response('', Array) #1 phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests.php(381): Requests_Transport_cURL->request('https://www.bin...', Array, NULL, Array) #2 /home/xxxx/public_html/yyyy/wp-includes/class-wp-http.php(395): Requests::request('https://www.bin...', Array, NULL, 'GET', Array) #3 /home/xxxx/public_html/yyyy/wp-includes/http.php(145): WP_Http->request('https://www.bin...', Array) #4 /home/xxxx/public_html/yyyy/wp-content/plugins/xml-sitemap-feed/models/functions.shared.php(125): wp_remote_request('https://www.bin...') #5 /home/xxxx/public_html/yyyy/wp-content/plugins/xml-sitemap-feed/controller in phar:///home/xxxx/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php on line 443 PHP Warning: opendir(/home/xxxx/public_html/yyyy/wp-content/uploads/wpcf7_uploads/): failed to open dir: Too many open files in /home/xxxx/public_html/yyyy/wp-content/plugins/contact-form-7/includes/file.php on line 359 Warning: opendir(/home/xxxx/public_html/yyyy/wp-content/uploads/wpcf7_uploads/): failed to open dir: Too many open files in /home/xxxx/public_html/yyyy/wp-content/plugins/contact-form-7/includes/file.php on line 359
臭いプラグインを読み込まないようにしてwp cliを実行する
wp cliはthemeやpluginを読み込まないオプションがあります。
特定のプラグインだけ読み込まないこともできますので、それで対応します。
wp eval-file xxxx.php --skip-plugins=xml-sitemap-feed
ファイルの開きすぎでアボートする
Too many open files
というエラーでアボートする場合は、ファイルを開ける制限の上限を上げて回避します。
exec('ulimit -S -n 2048');

Fatal Error - Too many open files
I try to run PHPUnit Tests in my new machine and I get this error: PHP Fatal error: Uncaught exception 'UnexpectedValueE...
Goutteなどのライブラリを使っている
Goutteなどのhttpクライアントライブラリなどを使っている場合、ファイル数が多すぎますというエラーが出やすいようでした。
PHPのnative DOMを使うと問題が解決します。
まとめ
wp cliで異常終了したときは、原因がよくわからないことが多いですが、wp cliのバグの可能性は低いです。
ほとんどの場合はコアの機能とは関係ない部分が原因だと思いますので、テーマやプラグインを読み込まないようにすることで対応できると思います。
ただ、処理に必要なものまで読み込まなくしてしまうと処理が成立しなくなりますので、そこは切り分けが必要になるでしょう。