Using Drush without json_decode/json_encode enabled.
Did you know that drush requires json support to be enabled in php?
Well, I did not until today.
Fatal error: Call to undefined function json_encode() in /home/drush/includes/output.inc on line 380
Drush command terminated abnormally due to an unrecoverable error.
Error: Call to undefined function json_encode() in /home/drush/includes/output.inc, line 380
If you have root or if your in good terms with your sysadmin, the good solution would be to enable json to your php. Either recompile php or install json using pecl or using your distribution's package manager (yum, rpm, apt, whatever).
Well, I did not have root on that machine so here is what I did.
First I installed pear's Services_JSON package.
Second, I created a file called json.php with the following content found here:
<?phpif ( !function_exists('json_decode') ){
function json_decode($content, $assoc=false){
require_once 'Services/JSON.php';
if ( $assoc ){
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
} else {
$json = new Services_JSON;
}
return $json->decode($content);
}}if ( !function_exists('json_encode') ){
function json_encode($content){
require_once 'Services/JSON.php';
$json = new Services_JSON;
return $json->encode($content);
}}
Then I created a /.drush/ folder in my home directory and I created a file called php.ini inside that folder.
mkdir ~/.drush
emacs ~/.drush/php.ini
You can use vi if your one of those :)
I put the following inside the file:
auto_prepend_file="/path/to/json.php"
where /path/to/ is the real path of where I put the json.php file above.
That was all and now I could use drush!