I just wanted to document my workaround for those not using php 5.2.x. For my sins I'm developing on a dedicated server with Fasthosts which runs php 5.1.6 and there is no easy way to update to update it.

Anyway, turns out apach solr only requires one (or maybe two) extra functions, namely json_decode().

I found this fix: http://my.php.net/manual/en/function.json-decode.php#80606

Place this into template.php:

<?php
if ( !function_exists('json_decode') ){
    function json_decode($content, $assoc=false){
                require_once 'json/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 place this script in the directory of your choice: http://pear.php.net/pepr/pepr-proposal-show.php?id=198 (under links > PEAR package file (.tgz))

Apologies for the dodgy labelling of this issue, I just wanted to save other people the hours of headbanging we went through. If anyone with extensive Solr knowledge has anything to point out about this, I would be grateful for the feedback.

Thanks,
Neil

Comments

ncameron’s picture

Update:

This was working fine for the search but I could not view the page admin/settings/apachesolr/index

I tried adding the same thing to the admin theme but that didn't work.

In the end I added it to the /sites/all/modules/apachesolr/response.php file and created the json directory there.

Is this worth packaging into a patch and adding to the project?

JacobSingh’s picture

Hi,

This is really needed, however can you try to find a replacement for the json_* which is not using PEAR? Since there is already an additional DL required, we'd like to avoid forcing someone to grab PEAR libs too.

Thanks,
Jacob

pwolanin’s picture

There is a core functions for going to JSON, but it adds an extra encoding step that might break us.

http://api.drupal.org/api/function/drupal_to_js/6

Since PHP 5.2 basically incorporates the earlier PEAR lib, I think requiring that lib and supporting it is really the sensible solution. Yes, it's an extra download, but so what?

pwolanin’s picture

The PEAR lib is this one: http://pecl.php.net/package/json

download: http://pecl.php.net/get/json-1.2.1.tgz

This is what was included in PHP 5.2. Seems to be a .so, however, so you'd need server admin access to install it into PHP.

pwolanin’s picture

StatusFileSize
new4.51 KB

Here's a new patch - updates the README to suggest either using the PECL extension, or supports using the Zend framework Json code.

pwolanin’s picture

StatusFileSize
new4.63 KB

This patch was tested (with a little hack) and seems to work.

JacobSingh’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

pwolanin’s picture

Status: Reviewed & tested by the community » Fixed

committing to 6.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.