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

Is storing objects in cache supported? my script fails hard #980

Closed
firstactivemedia opened this issue Aug 2, 2013 · 14 comments
Closed

Comments

@firstactivemedia
Copy link

I am experimenting with caching config objects in memcache to see if it increases speed or not when I came across a bug.

The code below is standalone stripped out of my site to run on command line just to test. The actual config I want to store is much bigger but the bug shows here too.

When the code runs, the config file is saved to the cache fine, I can see it with telnet and when I run

    $memcache_obj = new Memcache;
    $memcache_obj->connect('127.0.0.1', 11211);
    $config = $memcache_obj->get($key);

it comes back just fine, but I can't retrieve the config file with phalcon. (if I set the key value to "hello world" it works fine)

But worse it fails with no error message. I have error logging to show everything end even log to file. I wrote a call to a function that doesn't exist and it does show on both the command line and the php error log so I know that is working.

I believe I have ruled everything, and it has to be a phalcon issue.

<?php
$key = 'config';

$front = new Phalcon\Cache\Frontend\Data(array(
    "lifetime" => 3600
));
//Create the Cache setting memcached connection options
$cache = new Phalcon\Cache\Backend\Memcache($front, array(
    'host' => 'localhost',
    'port' => 11211,
    'persistent' => false
));

if($cache->exists($key))
{
    echo 'getting ',$key," from cache! we do get here if the key exists \n";
    $config = $cache->get($key);

    echo "this never runs, (and never shows an error)  :-( the script ends before here \n";
}

if(empty($config))
{
    $config = new \Phalcon\Config(array(
        'database' => array(
            'adapter'  => 'Mysql',
            'host'     => 'localhost',
            'username' => 'test',
            'password' => 'test',
            'name'     => 'test',
        ),

        'application' => array(
            'controllersDir' => __DIR__ . '/../../app/controllers/',
            'modelsDir'      => __DIR__ . '/../../app/models/',
            'viewsDir'       => __DIR__ . '/../../app/views/',
            'pluginsDir'     => __DIR__ . '/../../app/plugins/',
            'libraryDir'     => __DIR__ . '/../../app/library/',
            'baseUri'        => '/',
        )
    ));
    $cache->save($key, $config);
}

echo '$config : ',gettype($config),"\n";
print_r($config);

I am on fedora14 - 32 bit with the latest master. if I do a git pull I get told it is up to date and git show master says the last commit was : da5d779

@firstactivemedia
Copy link
Author

In case I wasn't clear when run as part of a webpage it causes Chrome to say Error code: ERR_EMPTY_RESPONSE ... even if there is output earlier in the page

@ghost
Copy link

ghost commented Aug 2, 2013

Could you please try 1.2.2? I believe it is b04d46b

@ghost
Copy link

ghost commented Aug 2, 2013

Never mind, I can confirm the crash.

@ghost
Copy link

ghost commented Aug 2, 2013

Fixed in a2c5980 (1.2.2) and 1be6ab9 (1.3.0)

@ghost
Copy link

ghost commented Aug 4, 2013

Did it work for you?

@firstactivemedia
Copy link
Author

Sorry for the delay, different timezones I think, plus had the weekend off ;)

Still have the same problem on master and 1.2.2, and have an extra issue with 1.3 which seems to stop it being installed altogether #1001

though based on your pull request title I have also tested with the simpler code as below and have the same issue - dies with no error during unserialize

<?php
$config = new \Phalcon\Config(array(
    'database' => array(
        'adapter'  => 'Mysql',
        'host'     => 'localhost',
        'username' => 'test',
        'password' => 'test',
        'name'     => 'test',
    ),

    'application' => array(
        'controllersDir' => __DIR__ . '/../../app/controllers/',
        'modelsDir'      => __DIR__ . '/../../app/models/',
        'viewsDir'       => __DIR__ . '/../../app/views/',
        'pluginsDir'     => __DIR__ . '/../../app/plugins/',
        'libraryDir'     => __DIR__ . '/../../app/library/',
        'baseUri'        => '/',
    )
));

echo 'Phalcon version : ',\Phalcon\Version::get(),"\n\n";
echo 'Phalcon version id : ',\Phalcon\Version::getId(),"\n\n";

$s = serialize($config);
$config = unserialize($s);
print_r($config);

Phalcon version : 1.2.2
Phalcon version id : 1020240

@ghost
Copy link

ghost commented Aug 5, 2013

$ php test.php 
Phalcon version : 1.3.0 ALPHA 1

Phalcon version id : 1030011

Phalcon\Config Object
(
    [database] => Phalcon\Config Object
        (
            [adapter] => Mysql
            [host] => localhost
            [username] => test
            [password] => test
            [name] => test
        )

    [application] => Phalcon\Config Object
        (
            [controllersDir] => /home/vladimir/workspace/cphalcon/../../app/controllers/
            [modelsDir] => /home/vladimir/workspace/cphalcon/../../app/models/
            [viewsDir] => /home/vladimir/workspace/cphalcon/../../app/views/
            [pluginsDir] => /home/vladimir/workspace/cphalcon/../../app/plugins/
            [libraryDir] => /home/vladimir/workspace/cphalcon/../../app/library/
            [baseUri] => /
        )

)

@firstactivemedia
Copy link
Author

I tried the script on a 64 bit system

Phalcon version : 1.3.0 ALPHA 1
Phalcon version id : 1030011

still same problem

Also on the 32 bit system 1.3 seems to work on command line despite #1001 but it doesn't fix this issue

@ghost
Copy link

ghost commented Aug 5, 2013

I also run the script on 64-bit system… What git revision do you use?

@ghost
Copy link

ghost commented Aug 5, 2013

BTW, could you please build phalcon for ext/? build/ files are not regenerated often, ext/ is always fresh

@ghost
Copy link

ghost commented Aug 5, 2013

Just tested 1.2.2

Phalcon version : 1.2.2

Phalcon version id : 1020240

Phalcon\Config Object
(
    [database] => Phalcon\Config Object
        (
            [adapter] => Mysql
            [host] => localhost
            [username] => test
            [password] => test
            [name] => test
        )

    [application] => Phalcon\Config Object
        (
            [controllersDir] => /home/vladimir/workspace/cphalcon/../../app/controllers/
            [modelsDir] => /home/vladimir/workspace/cphalcon/../../app/models/
            [viewsDir] => /home/vladimir/workspace/cphalcon/../../app/views/
            [pluginsDir] => /home/vladimir/workspace/cphalcon/../../app/plugins/
            [libraryDir] => /home/vladimir/workspace/cphalcon/../../app/library/
            [baseUri] => /
        )

)

1.2.2 is 7915b80
1.3.0 is c800012

All built from ext/

@firstactivemedia
Copy link
Author

"could you please build phalcon for ext/?"

sorry not sure how? Also what is the best way to find the git revision?

@ghost
Copy link

ghost commented Aug 5, 2013

git clone https://github.com/phalcon/cphalcon.git
git checkout 1.3.0
cd ext
phpize
./configure
make
sudo make install

for 1.2.2 — git checkout 1.2.2

@firstactivemedia
Copy link
Author

Cool, that's fixed now, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant