Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

HanXHX opened this issue Aug 31, 2016 · 7 comments
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@HanXHX
Copy link

HanXHX commented Aug 31, 2016

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
Copy link
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
Copy link
Contributor

sergeyklay commented Aug 31, 2016

@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
Copy link
Author

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
Copy link
Contributor

stamster commented Sep 1, 2016

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

@Jurigag
Copy link
Contributor

Jurigag commented Sep 1, 2016

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

@stamster
Copy link
Contributor

stamster commented Sep 1, 2016

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

@Jurigag
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

5 participants