Bug (3.0.1) : Phalcon cache with backend memory #12186

Closed
HanXHX opened this Issue Aug 31, 2016 · 7 comments

Projects

None yet

4 participants

@HanXHX
HanXHX commented Aug 31, 2016 edited

Expected and Actual Behavior

Since Phalcon 3.0.1, I have an issue with backend cache memory. It works well on 3.0.0.

Test file:

<?php

use Phalcon\Cache\Frontend\Data as Phalcon_Cache_Front;
use Phalcon\Cache\Backend\Memory as Phalcon_Cache_Back;


$frontend = new Phalcon_Cache_Front(["lifetime" => 120]);
$backend = new Phalcon_Cache_Back($frontend);

echo Phalcon\Version::get() . "\n";

var_dump($backend->save('a', 1));
var_dump($backend->get('a'));

With Phalcon 3.0.0 (OK no problem).

3.0.0
/tmp/toto.php:12:
bool(true)
/tmp/toto.php:13:
int(1)

With Phalcon 3.0.1

3.0.1
/tmp/toto.php:12:
bool(true)
PHP Notice:  unserialize(): Error at offset 0 of 1 bytes in /tmp/toto.php on line 13
PHP Stack trace:
PHP   1. {main}() /tmp/toto.php:0
PHP   2. Phalcon\Cache\Backend\Memory->get() /tmp/toto.php:13
PHP   3. Phalcon\Cache\Frontend\Data->afterRetrieve() /tmp/toto.php:13
PHP   4. unserialize() /tmp/toto.php:13
/tmp/toto.php:13:
bool(false)

Details

  • Phalcon version: 3.0.1
  • PHP Version: 7.0.*
  • Operating System: Tested on Ubuntu / Debian
  • Installation type: via package manager
@Jurigag
Contributor
Jurigag commented Aug 31, 2016

@sergeyklay Isn't this because php is trying to unserialize not serialized content ? https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/backend/memory.zep#L110

Fix is to check here if data is not numeric https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/frontend/data.zep#L137 if it is just return data.

@sergeyklay sergeyklay added this to the 3.0.2 milestone Aug 31, 2016
@sergeyklay sergeyklay self-assigned this Aug 31, 2016
@sergeyklay
Collaborator
sergeyklay commented Aug 31, 2016 edited

@HanXHX
Could you please check 3.0.x branch?

git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build
@HanXHX
HanXHX commented Sep 1, 2016
hanx@emantel:~/tmp/cphalcon{0} (3.0.x *)$ php -d./ext/modules/phalcon.so /tmp/toto.php 
3.0.2
/tmp/toto.php:12:
int(1)
/tmp/toto.php:13:
string(1) "1"

It works now. Do you have a release date for 3.0.2?

@stamster
stamster commented Sep 1, 2016 edited

Have you tried with another cache adapter, i.e. libmemcached?

@Jurigag
Contributor
Jurigag commented Sep 1, 2016

@stamster this is because not cache backend adapter. It's because frontend data, it's already fixed.

@stamster
stamster commented Sep 1, 2016

Sure, I'm curious whenever this frontend adapter would work: \Phalcon\Cache\Frontend\Json

@Jurigag
Contributor
Jurigag commented Sep 1, 2016

Yes, it's not a problem with json, this is only because of data. Just backend adapters where saving not serialized numeric values, but frontend data was trying to unserialize them anyway. Now it's fixed.

@sergeyklay sergeyklay closed this Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment