最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

command line - wp-cli displays php notices when display errors off

programmeradmin1浏览0评论

I am using wp-cli and I am having php notices and errors show up when running wp-export. Some of these warnings and errors are ending up in the output file. How can I force errors to NOT show up. I have tried ini_set('display_errors', 0); and error_reporting(0); in wp-wp-config.php

root@roc-apache-4:/var/www/blogs/html# wp export --quiet=true --debug=false --url=/ --dir=/root/wordpress_exports --file_item_count=100000000
PHP Notice:  date_default_timezone_set(): Timezone ID 'America/New York' is invalid in phar:///usr/bin/wp/php/wp-cli.php(21) : eval()'d code on line 16
PHP Notice:  Constant ABSPATH already defined in phar:///usr/bin/wp/php/wp-cli.php(21) : eval()'d code on line 68
PHP Notice:  Undefined index: combineCommentCounts in /var/www/blogs/html/wp-content/plugins/facebook-comments-for-wordpress/facebook-comments.php on line 265

Notice: Undefined index: combineCommentCounts in /var/www/blogs/html/wp-content/plugins/facebook-comments-for-wordpress/facebook-comments.php on line 265
PHP Notice:  define() was called with an argument that is <strong>deprecated</strong> since version 3.0! The constant <code>VHOST</code> <strong>is deprecated</strong>. Use the boolean constant <code>SUBDOMAIN_INSTALL</code> in wp-config.php to enable a subdomain configuration. Use is_subdomain_install() to check whether a subdomain configuration is enabled. in /var/www/blogs/html/wp-includes/functions.php on line 3466

I am using wp-cli and I am having php notices and errors show up when running wp-export. Some of these warnings and errors are ending up in the output file. How can I force errors to NOT show up. I have tried ini_set('display_errors', 0); and error_reporting(0); in wp-wp-config.php

root@roc-apache-4:/var/www/blogs/html# wp export --quiet=true --debug=false --url=http://blogs.democratandchronicle/fleet-feet-beat/ --dir=/root/wordpress_exports --file_item_count=100000000
PHP Notice:  date_default_timezone_set(): Timezone ID 'America/New York' is invalid in phar:///usr/bin/wp/php/wp-cli.php(21) : eval()'d code on line 16
PHP Notice:  Constant ABSPATH already defined in phar:///usr/bin/wp/php/wp-cli.php(21) : eval()'d code on line 68
PHP Notice:  Undefined index: combineCommentCounts in /var/www/blogs/html/wp-content/plugins/facebook-comments-for-wordpress/facebook-comments.php on line 265

Notice: Undefined index: combineCommentCounts in /var/www/blogs/html/wp-content/plugins/facebook-comments-for-wordpress/facebook-comments.php on line 265
PHP Notice:  define() was called with an argument that is <strong>deprecated</strong> since version 3.0! The constant <code>VHOST</code> <strong>is deprecated</strong>. Use the boolean constant <code>SUBDOMAIN_INSTALL</code> in wp-config.php to enable a subdomain configuration. Use is_subdomain_install() to check whether a subdomain configuration is enabled. in /var/www/blogs/html/wp-includes/functions.php on line 3466
Share Improve this question edited Aug 16, 2013 at 4:20 Wyck 18k4 gold badges46 silver badges67 bronze badges asked May 21, 2013 at 16:39 Chris MuenchChris Muench 1911 gold badge1 silver badge4 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 4

First, you have to do your PHP error settings in your php.ini file unless the PHP ini directives don't list it as PHP_INI_ALL - which is the case for nearly error related definition.

So I'm assuming you just misread something and set stuff to wp_settings.php instead of wp-config.php.

The next point is that WP CLI might run WP in different cases without some stuff loaded, so it could get bypassed.

The safest point to set some php.ini stuff always is your php.ini file. And if you can't work around errors: Go and fix them - that's what errors, warnings and notices are for. If it's a plugin causing it, send a pull request and notify the author.


Note: If you are in/on your Terminal/Command Line, you can use php --ini to list all locations where your php.ini files are stored. Some operating systems support different locations per default. And some packages like XDebug have additional locations per default.

Example php --ini result on Windows:

Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         C:\dev\php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Example php --ini result on Ubuntu 12.04 LTS:

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-curl.ini,
/etc/php5/cli/conf.d/20-gd.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-mysql.ini,
/etc/php5/cli/conf.d/20-mysqli.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini,
/etc/php5/cli/conf.d/20-readline.ini,

You can use the --require= argument to include a file that sets error reporting level and whether or not to display errors. I did something similar to this in a shell script:

# Suppress errors by including this generated file
echo "<?php error_reporting(0); @ini_set('display_errors', 0);" > __pre.php

rc=0

for i in 905 1000 10001; do
    wp --quiet --no-color --user=admin --require=./__pre.php \
        post update $i --post_status=draft \
           || (rc=1 && break)
done

rm -f __pre.php
exit $rc

Note the ./ because it will not default to the local path but will use PHP's include_path. Need to bypass that in this case.

If you do not suppress the errors, any PHP notice will cause an exit status of non-zero. Not desirable in my case because I want the loop to stop as soon as any real error occurs.

My solution to disable notices etc is to know if the wp-config.php is call via cli or not. So put this little code in wp-config.php

$sapi_type = php_sapi_name();
if ( $sapi_type == 'cli' ) {
    define( 'WP_DEBUG', false );
} else {
    define( 'WP_DEBUG', true );
}

There are likely 2 php.ini files

  • /etc/php/7.0/cli/php.ini This is for your Command Line Interface (CLI)
  • /etc/php/7.0/apache2/php.ini This is for your Web Server, in this case Apache2

To update what errors are reported on the command line, update the error_reporting line in the cli/php.ini

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>