Comments

pounard’s picture

Oh right... I changed all class_exists("¨Predis::client") to class_exists("Predis\Client"). I remember that in the old days I got serious problems PHP wasn't finding "¨Predis\Client" but was finding "Predis::Client" but now the exact opposite is happening on my box, it seems that you are experiencing what I was experiencing a long time ago...

Can you paste here the revelant changes you made to your settings.php file please?

Can you also give me the PHP version you're using?

Waiting for your answer.

pierrepaul’s picture

We stumbled on the bug together, but in my case alpha11 isn't working either.
I've kept my settings.php to the bare minimum :

$conf['cache_backends'][]            = 'sites/all/modules/contrib/redis/redis.autoload.inc';
$conf['redis_client_interface']      = 'Predis';                                
$conf['redis_client_host'] = '127.0.0.1';                                       
$conf['redis_client_port'] = '6379';                                            
                                                                                
$conf['cache_class_cache']           = 'Redis_Cache';                           
$conf['cache_class_cache_menu']      = 'Redis_Cache';                           
$conf['cache_class_cache_bootstrap'] = 'Redis_Cache';

It might have something to do with my PHP version though : PHP 5.4.6

pounard’s picture

Ok thanks a lot, I will try to solve that before the end of the week thought I cannot promise anything. I'm coming back to you ASAP.

pounard’s picture

I have to admit that autoloading handling is quite ugly in this module. Bug is arround that.

pbuyle’s picture

Can X Autoload help or is the auto-loading of Predis needed too early in the bootstrap process?

pounard’s picture

I think Predis is needed too early for that, hook_boot() is run long after first hits to the cache system have been done.

pbuyle’s picture

If you look at the stacktrace, Redis_Client_Predis::getClient() is invoked twice (14 and 23). And the class load failure happens during the second invocation. Now that second invocation happens during the class_exists() invocation made by Redis_Client_Predis::setPredisAutoload()(17). PHP tries to load the Predis\Client class using drupal_autoload_class() (18) which itself end up calling Redis_Client_Predis::getClient() (24) as part of the code registry caching (19 to 23). I guess PHP is avoiding infinite recursion here and returns TRUE for the second class_exists() invocation. Preventing Redis_Client_Predis::setPredisAutoload() from registering its autoload function and so Predis\Client is not loaded before being used.

Using FALSE as second argument for class_exists() to avoid using autoload solve the issue on my side.

I guess using the "::" syntax works because, at least on my PHP version, it does not work as a namespace separator. So drupal_autoload_class() is not used to (try to) load Predis\Client, and Redis_Client_Predis::setPredisAutoload() succeed in registering its autoload function before Predis\Client is used.

pbuyle’s picture

Status: Active » Needs review
StatusFileSize
new938 bytes

See #7

pounard’s picture

Status: Needs review » Closed (cannot reproduce)

Is this bug still a bug? It seems that latest releases may have fixed it. I'm closing it as "cannot reproduce" please re open if this happens with the latest release.

aangel’s picture

Status: Closed (cannot reproduce) » Active

Re-opening because this is occurring for me with:
- php 5.4.10
- redis 7.x-2.0-beta4

Stack trace:
 ! ) Fatal error: Class 'Predis\Client' not found in /Users/aangelantoni/Sites/base/sites/all/modules/redis/lib/Redis/Client/Predis.php on line 89
Call Stack
#	Time	Memory	Function	Location
1	0.0455	650744	_drupal_exception_handler( )	../bootstrap.inc:0
2	0.0489	689440	_drupal_log_error( )	../bootstrap.inc:2259
3	0.0493	689728	drupal_maintenance_theme( )	../errors.inc:194
4	0.0501	714936	_drupal_maintenance_theme( )	../bootstrap.inc:2501
5	0.1058	3000712	list_themes( )	../theme.maintenance.inc:57
6	0.1059	3001656	_system_rebuild_theme_data( )	../theme.inc:795
7	0.1278	3019528	module_invoke_all( )	../system.module:2483
8	0.1278	3019944	module_implements( )	../module.inc:847
9	0.1278	3020944	cache_get( )	../module.inc:692
10	0.1285	3084288	Redis_Cache->get( )	../cache.inc:56
11	0.1286	3084336	Redis_Cache_Predis->get( )	../Cache.php:18
12	0.1286	3084456	Redis_Client::getClient( )	../Predis.php:9
13	0.1286	3084840	Redis_Client_Predis->getClient( )	../Client.php:126
aangel’s picture

Status: Active » Closed (cannot reproduce)

Never mind...newbie install mistake. Was missing predis library.

pounard’s picture

Hehe, don't worry this kind of mistake happens to all of us. Happy it works for you. Thanks for bothering opening the issue thought, even if it's not.

hiramanpatil’s picture

Facing issue with below versions-

Redis version - 7.x-2.6
PHP version - 5.2.10 and 5.3.12
Drupal - 7.27
There is no issue with live site which is on pantheon but when I trying to setup it on local environment it gives errors.

Fatal error: Class 'Redis' not found in /ROOT_PATH/sites/all/modules/redis/lib/Redis/Client/PhpRedis.php on line 9

Please help me on this.

Thanks

rene bakx’s picture

I just had the same issue, and the manual for predis is not really up to date with the current state of the library.

What I did was, cloned https://github.com/nrk/predis into a temp folder, then copied the src folder in to my libraries folder. Renamed src into Predis (mind the capital P)
So I ended up with Predis being in /sites/all/Predis and

see http://imgur.com/ozNOcda

Secondly I added the following lines in the bottom of settings.php, and the first line is important.

  define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/');
  $conf['redis_client_interface'] = 'Predis'; // Can be "Predis".
  $conf['redis_client_host']      = '127.0.0.1';  // Your Redis instance hostname.
  $conf['lock_inc']               = 'sites/all/modules/contrib/redis/redis.lock.inc';
  $conf['path_inc']               = 'sites/all/modules/contrib/redis/redis.path.inc';
  $conf['cache_backends'][]       = 'sites/all/modules/contrib/redis/redis.autoload.inc';
  $conf['cache_default_class']    = 'Redis_Cache';

As a side note, i use the xautoload module on all my projects, so Iam not 100% sure if this trick will work without it. But if I disable xautoload, the rest of my site WSOD's :)

floretan’s picture

Status: Closed (cannot reproduce) » Needs review
StatusFileSize
new1.39 KB

The location of the files within the Predis library has changed from "lib" to "src" (see https://github.com/nrk/predis/commit/029822fe22acac3a769f14a11f417d9a083...).

Given that there is now a stable 1.0 release of Predis, we can assume that new users will install that version by default. We should just notify existing users updating the redis module that they should also update the Predis library.

floretan’s picture

Status: Needs review » Closed (cannot reproduce)

While the initial symptoms are the same (class not found), there is already an issue for the 1.0 compatibility: #2329055: Compatibility with Predis 1.x

garnett2125’s picture

StatusFileSize
new703 bytes

Here is a patch I needed

garnett2125’s picture

garnett2125’s picture

StatusFileSize
new722 bytes

Repository structure have change in the Predis librarie https://github.com/nrk/predis
So I needed to apply this patch for it to works.

I also needed to change PREDIS_BASE_PATH because the folder is no longer libraries/predis/lib/ but libraries/predis/src/ (by default if you don't define this var it will be DRUPAL_ROOT . '/sites/all/libraries/predis/lib/' which doesn't exist)

Hope it helps

pounard’s picture

Oups forgot about this, I need to review it.

candelas’s picture

Good I found this. I was getting errors because of lib instead of src. Thanks @garnett2125
I hope it gets in dev, so new users will go faster :)

candelas’s picture

Version: 7.x-2.0-beta1 » 7.x-2.12
Status: Closed (cannot reproduce) » Needs review

patch #19 worked library Predis 1.0.2-dev and writing the src correction in settings.php

define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/predis/src/');

candelas’s picture

The patch is still required because if not you get
Fatal error: require_once(): Failed opening required '/xxx/sites/all/libraries/predis/src/Predis/Client.php

To avoid the problem with having to set

define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/predis/src/');

the #2329055: Compatibility with Predis 1.x should be ported to 7.x-2.x (it is only in 7.x-3.x)

I hope it helps someone :)

pounard’s picture

Status: Needs review » Active

It happens that I accidentally experienced the bug on a project, and it is the only one it actually happens. Somehow, the !class_exists('Predis\Client') condition fails on this environment where it should not, and the bug triggers; but this is nothing that can be solved by the previous 2 patches... I still need to investigate this further.

pivica’s picture

Hmm using redis 7.x-2.15 and predis 1.0.1 and each time i execute drush cc all getting next error

Class 'Predis\Client' not found in .../sites/all/modules/contrib/redis/lib/Redis/Client/Predis.php on line 132
PHP Stack trace:
PHP   1. _drupal_exception_handler() .../includes/bootstrap.inc:0
PHP   2. _drupal_log_error() .../includes/bootstrap.inc:2333
PHP   3. drupal_maintenance_theme() .../includes/errors.inc:179
PHP   4. _drupal_maintenance_theme() .../includes/bootstrap.inc:2593
PHP   5. list_themes() .../includes/theme.maintenance.inc:57
PHP   6. _system_rebuild_theme_data() .../includes/theme.inc:798
PHP   7. module_invoke_all() .../modules/system/system.module:2507
PHP   8. module_implements() .../includes/module.inc:892
PHP   9. cache_get() .../includes/module.inc:723
PHP  10. Redis_Cache->get() .../includes/cache.inc:56
PHP  11. Redis_Cache_Predis->get() .../sites/all/modules/contrib/redis/lib/Redis/Cache.php:18
PHP  12. Redis_Client::getClient() .../sites/all/modules/contrib/redis/lib/Redis/Cache/Predis.php:10
PHP  13. Redis_Client_Predis->getClient() .../sites/all/modules/contrib/redis/lib/Redis/Client.php:163
Drush command terminated abnormally due to an unrecoverable error.                                                                                      [error]
Error: Class 'Predis\Client' not found in .../sites/all/modules/contrib/redis/lib/Redis/Client/Predis.php, line 132
duaelfr’s picture

Version: 7.x-2.12 » 7.x-3.9

Same issue with
- Redis 7.x-3.9
- Predis 1.0.3
- PHP (fpm) 5.6.9

I don't know what's going on but if I copy the spl_autoload_register() call from Predis::setPredisAutoload() to redis.autoload.php it works.

My only workaround for now is to include the Predis' autoload.php directly in my settings.php as follows:

define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/predis/');
require_once PREDIS_BASE_PATH . '/autoload.php';
duaelfr’s picture

Version: 7.x-3.9 » 7.x-3.x-dev

Confirmed on 7.x-3.x

pounard’s picture

Ok, thanks for the additional details, I'll try to look into this a bit deeper as soon as I can.

weri’s picture

The "comment" from DuaelFr (#26) solves the problem, but is not a final solution.

  • Pierre.R committed be5b876 on 7.x-3.x authored by pounard
    Issue #1839434 by garnett2125, pbuyle, floretan, pounard, DuaelFr, weri...
pounard’s picture

Status: Active » Fixed

Ok this now should be fixed, please wait for the next release (today or tomorrow). Thanks everyone for your patience and all the help you've given.

For your information, the bug is due to the core autoloader, when the Redis_Client_Predis::setPredisAutoload() method is called for the first time and the core autoloader is registered (i.e. if you didn't set the page_cache_without_database variable or you are logged in), core autoloader will attempt a cache_get() call. Because the Predis discovery has already be run once, it won't try a second time, and fail to load the class during the core autoloader recursion.

I had to write a very ugly patch to make this work, the real bug is a core one, an autoloader should never trigger another one, and rely upon database and cache for autoloading creates a chicken and egg problem which causes such ambiguous issues.

Please if the next release does not fix the problem, please re-open this issue.

cola’s picture

Issue summary: View changes

Hi All

We use Redis and not Predis. Did you solve also the issue for Redis class?

drush status
PHP Fatal error: Class 'Redis' not found in ../sites/default/settings.php on line 587
Fatal error: Class 'Redis' not found in ../sites/default/settings.php on line 587
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Class 'Redis' not found in ../sites/default/settings.php, line 587

Thank you for your answer

pounard’s picture

@cola if you experience such errors then the phpredis extension is not enabled in your PHP runtime, check that you have installed the phpredis extension and that you correctly enabled it in your PHP ini files.

Status: Fixed » Closed (fixed)

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