hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Bad memcached key prefix in memcached.sess_prefix

Open florianbeer opened this issue 11 years ago • 4 comments

I am using Memcached for session storage and experiencing the following error (in my application error log), when trying to initiate a login on my page:

Bad memcached key prefix in memcached.sess_prefix

var_dump(ini_get('memcached.sess_prefix')) gives me the correct value I've set in /etc/hhvm/php.ini. I have tried setting it to an empty string, a short custom value and the default (memc.sess.key.) to no avail.

HHVM Version: 3.6.1

/etc/hhvm/php.ini:

; php options
session.save_handler = memcached
session.save_path = "127.0.0.1:11211"
;session.save_path = /var/lib/php5
session.gc_maxlifetime = 1440
memcached.sess_prefix = "memc.sess.key."

; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false
hhvm.mysql.socket = /var/run/mysqld/mysqld.sock

florianbeer avatar Apr 25 '15 10:04 florianbeer

You might have a hidden character in your ini file. If ctype_graph(trim((string)ini_get('memcached.sess_prefix'))) returns false, then that's the problem.

aingram avatar May 07 '15 10:05 aingram

Thanks, good idea but unfortunately that's not the case.

florianbeer avatar May 07 '15 10:05 florianbeer

I can't reproduce this. Could you please post a reproducible bit of code so I can run this in my debugger? Maybe something that shows the output from ini_get and ctype_graph and then calls session_start() to cause the error?

aingram avatar May 07 '15 17:05 aingram

Further testing seems that the problem is fixed now with the last hhvm update. I didn't change anything on the server config.

This is the code I am testing with:

<?php
echo 'var_dump(ini_get("memcached.sess_prefix"))';
var_dump(ini_get('memcached.sess_prefix'));
echo 'var_dump(ctype_graph(trim((string)ini_get("memcached.sess_prefix"))));
var_dump(ctype_graph(trim((string)ini_get('memcached.sess_prefix'))));
flush();
session_start();
$_SESSION['test'] = 'This is a Session var';
echo '<a href="page2.php">Page 2</a>';

Page 2 then only calls session_start() and writes out $_SESSION['test'].

The code results in the following error in /var/log/hhvm/error.log if I don't set memcached.sess_prefix:

\nWarning: Bad memcached key prefix in memcached.sess_prefix in /var/www/hhvm/index.php on line 7
\nWarning: Failed calling MemcachedSessionModule::open() in /var/www/hhvm/index.php on line 7
\nFatal error: Failed to initialize storage module: memcached (path: 127.0.0.1:11211) in /var/www/hhvm/index.php on line 7

You can view the code in action here: http://hhvm.42dev.net

If I set memcached.sess_prefix in hhvm.ini all seems to be well now. Thank you very much for you help!

florianbeer avatar May 07 '15 19:05 florianbeer