We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

APC metadata breakage on Model save, The meta-data is invalid or is corrupt, Phalcon 2.0, Postgresql

Greetings,

I recently upgraded from 1.3 to 2.0 and am now experiencing errors from the APC metdata cache when I do a basic model save. Everything worked fine in 1.3 and it also works fine if I remove the APC cache service. Below is the error, stack trace, and some relevant code. Please let me know if I can provide further information. Help/ideas/direction are greatly appreciated!

Best,

-b

error and stack trace

Undefined index: 1 in phalcon/mvc/model/metadata.zep on line 288 in <b>/Users/bbrown/projects/andrina/web/phalcon_apps/admin/api/index.php</b> on line <b>171</b><br />
{"error_msg":"The meta-data is invalid or is corrupt","error_trace":"#0 [internal function]: Phalcon\\Mvc\\Model\\MetaData->getPrimaryKeyAttributes(Object(RestEntity))\n#1 [internal function]: Phalcon\\Mvc\\Model->_exists(Object(Phalcon\\Mvc\\Model\\MetaData\\Apc), Object(Phalcon\\Db\\Adapter\\Pdo\\Postgresql), 'tag')\n#2 \/Users\/bbrown\/projects\/andrina\/web\/phalcon_apps\/admin\/api\/index.php(171): Phalcon\\Mvc\\Model->save()\n#3 [internal function]: {closure}('tag', '1')\n#4 \/Users\/bbrown\/projects\/andrina\/web\/phalcon_apps\/admin\/api\/index.php(250): Phalcon\\Mvc\\Micro->handle()

some relevant code

use Phalcon\Mvc\Micro;
use Phalcon\DI\FactoryDefault;
use Phalcon\Config\Adapter\Yaml as YAMLConfig;
use Phalcon\Db\Adapter\Pdo\Postgresql as PostgresAdapter;
use Phalcon\Mvc\Model\MetaData\APC as ApcMetaData;
use Phalcon\Session\Adapter\Files as Session;

/**
 * service dispatcher
 */
$di = new FactoryDefault();

/**
 * load config file
 */
$di->set('config', function() {
    return new YAMLConfig(ANDRINA_ROOT."/etc/config.yml");
});

/**
 * db handle
 */
$di->set("db", function() use($di) {
    return new PostgresAdapter(array(
        "host"     => $di['config']->database->host,
        "username" => $di['config']->database->user,
        "password" => $di['config']->database->password,
        "dbname"   => $di['config']->database->name,
    ));
});

// db metadata caching
$di['modelsMetadata'] = function() {

    // Create a meta-data manager with APC
    $metaData = new ApcMetaData(array(
        "lifetime" => 86400,
        "prefix" => "andrina"
    ));

    return $metaData;
};

//Start the session
$di->setShared('session', function() {
    $session = new Session([
        'lifetime' => 3600 * 4
    ]);
    $session->start();
    return $session;
});

$app = new ApiMicro();
$app->setDI($di);

db table schema

andrina=> \d tag
                                   Table "public.tag"
 Column |          Type           |                      Modifiers
--------+-------------------------+------------------------------------------------------
 tag_id | integer                 | not null default nextval('tag_tag_id_seq'::regclass)
 name   | character varying(2044) | not null
Indexes:
    "tag_pkey" PRIMARY KEY, btree (tag_id)
    "tag_name_key" UNIQUE CONSTRAINT, btree (name)
edited Jul '15

Did you restart the web server?

Yes, when I restart the web server the first request works (when the caching happens), but all subsequent requests using the cache break with the error above. Looking at the stack trace I suspect there is some problem with this method: getPrimaryKeyAttributes(Object(RestEntity) and the Postgresql adapter? The model class RestEntity is general purpose where I first call setSource to point it to the correct table in the db.



199

I had similar issue on PHP 5.4.x with MySQL. I've removed the APC metadata and then it works.

edited Jul '17

Did you install igbinary? It works when I remark apc.serializer

;apc.serializer=igbinary

but... it works fine with apc_fetch() no matter remark that code or not My igbinary version is 2.0.1