Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Models Metadata in Opcache

Hi everybody, it is possible to cache models metadata in opcache ? APC is not supported on PHP7, and opcache is the best alternative. I use phalcon v3 and PHP7 on ubuntu 16.04.

Thanks



114.4k
Accepted
answer
edited Sep '16

Yes, apc is supported on PHP7. You just need to install apcu_bc from pecl and then change names of apc.ini and apcu.ini to make apc.ini being loaded after apcu.

Or just use memcached or redis because they are best alternative.

Just in apcu for php 7 there were removed APC emulation which was in apcu for php 5.x and it wasn't decoupled to apcu_bc.

edited Sep '16

@seitechsoftware: You need to understand that OPcache is not a regular cache subsystem for your app stuff like data from database etc.

The only important thing to remember when migrating from APC to OpCache is the fact that the latter doesn’t work as a data caching engine. If you have already implemented APC, you may be using its apc_add() and apc_fetch() functions which serve as an interface to a data caching service. OpCache is only a bytecode caching engine so it won’t offer a similar functionality. If you’re planning to switch from APC to OpCache, remember to consider this limitation.

OPcache stores precompiled script bytecode in the system memory. That means only code, not data (only literals). Actual data is being served at runtime from a database, file system etc.

For exact same purpose of caching models metadata I use (lib)Memcached. It works flawlessly. I would avoid APC* stuff.

As far as I understand, if in a production I define the models metadata manually and use OpCache - it should work faster, than using Memcached or Redis?

Is this assumption correct?

edited Apr '17

Faster yes - but it will use more memory i guess. Still the difference will be almost none comparedto memcached or redis and it's much easier to use them when having some big application imho.

edited Apr '17

Faster yes - but it will use more memory i guess. Still the difference will be almost none comparedto memcached or redis and it's much easier to use them when having some big application imho.

Thanks.

As far as I understand, if in a production I define the models metadata manually and use OpCache - it should work faster, than using Memcached or Redis?

Is this assumption correct?

Not quite. Models metadata is using some of the cache adapters to store metadata (i.e. your tables and columns definition). OPcache has nothing to do with Models metadata directly. You still need a certain data cache layer for such data, i.e. Memcached.

As far as I understand, if in a production I define the models metadata manually and use OpCache - it should work faster, than using Memcached or Redis?

Is this assumption correct?

Not quite. Models metadata is using some of the cache adapters to store metadata (i.e. your tables and columns definition). OPcache has nothing to do with Models metadata directly. You still need a certain data cache layer for such data, i.e. Memcached.

If you in model will define method metaData which will return array then you don't need any adapter, it won't be ever hit. S o opcache + metaData method will be fastest way, but it's dirty and bad.