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
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | json-5.1-392978-6.patch | 4.63 KB | pwolanin |
| #5 | json-5.1-392978-5.patch | 4.51 KB | pwolanin |
Comments
Comment #1
ncameron commentedUpdate:
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?
Comment #2
JacobSingh commentedHi,
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
Comment #3
pwolanin commentedThere 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?
Comment #4
pwolanin commentedThe 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.
Comment #5
pwolanin commentedHere's a new patch - updates the README to suggest either using the PECL extension, or supports using the Zend framework Json code.
Comment #6
pwolanin commentedThis patch was tested (with a little hack) and seems to work.
Comment #7
JacobSingh commentedLooks good.
Comment #8
pwolanin commentedcommitting to 6.x