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

Store states in Phalcon

I want to save some states of the application and the system as:

  • Modified date of a folder
  • The date of the last time it was run a CRON
  • etc...

Any good option to store this information?

Memcache/redis ?

You can start with simple files. Later move on to Memcached.

Some projects have a component keyValueStore and extends this to State component.

Although the best for now is to keep the states in a simple php file, perhaps using var_export ().

I created a service 'keyvalue:

My test:

 $storage = $this->keyvalue->get('state');
    $storage->set('mimi', [1, 'mimi']);
//    $storage->set('cerbero', [1,2,3,4]);
//    $storage->set('mimiz', "esto es un string");

    d($storage->getCollectionName());
    d($storage->getAll());
    d($storage->getMultiple(['mimi', 'cerbero']));
    d($storage->get('mimi'));
    d($storage->has('mimi'));
    d($storage->delete('mimiz'));
    d($storage->setMultiple([
        'tom' => ['soy', 'dios'],
        'garfield' => [1,2,3]
    ]));
    d($storage->rename('mimi', 'minimi'));


40.1k
Accepted
answer

extend keyvalue for state component

/**
     * @var \Druphal\Core\State\State $state
     */
    $state = $this->state;
    $state->delete('mimi');
    $state->set('system.date', time());
    $state->deleteMultiple(['mimi', 'mimi']);
    $state->get('mimi');
    $state->setMultiple([
        'system.not' => [1,2,3,4],
        'system.get' => 'mi mama me mima'
    ]);
    $state->getMultiple(['mimi']);

    d($state);