WordPress wp-cli generates error: “Call to undefined function getallheaders”

Solution:

Some PHP functions are dependent on the underlying Server Application Programming Interface. The Apache SAPI of course supports the getallheaders method. But some Command Line Interfaces do not. In this case wp-cli uses the PHP-FPM (FastCGI Process Manager) as the SAPI. However according to this PHP Bug Report 62596, PHP-FPM in PHP v5.4 does not support getallheaders. Therefore when wp-cli attempts to bootstrap the WordPress Site in CLI mode, the undefined function errors occurs.

The recommended solution is to add these lines to the wp-config.php file. The wp-cli tool defines a constant called: WP_CLI. If this constant is set then simply define a dummy version of the getallheaders. This should not cause a problem because the WP App is not getting any HTTP Headers anyway when running in CLI mode. Here is some sample code that can be inserted into wp-config.php

if ( defined( ‘WP_CLI’ ) ) {
if ( !function_exists ( ‘getallheaders’ ) ) {
function getallheaders() {return array();}
}
}