Opcache equivalent function to apc store - php

We need to upgrade the php version from 5.3 to 5.5 of one project that´s using APC. So, as I´ve seen in php 5.5 there is a new cache library to use instead of apc, opcache. I have read the docs and I have a few doubts.
Actually, in one specific part of the project we are using the apc store and fetch functions to store some data, but I haven´t seen any similar functions to do the same task with opcache. The question is simple, is it possible to do the same with opcache?
Thanks in advance.

You can restore the store and fetch functions by installing APCu
sudo apt-get install php5-apcu
By installing APCu extension_loaded('apc') will return true as well
and you don't need to rename any of the old functions used.
I'm using this on a debian with PHP5.6 with OPCache enabled
source

No you can not do it with OPCache. This module makes OPCode Caching only.

Related

Is there a PHP 5.5 buildpack with APC (Alternative PHP Cache)?

Can I use APC (Alternative PHP Cache) in my Bluemix PHP environment?
I added { "PHP_EXTENSIONS": ["apc"] } to my options.json file but when I tried that to deploy a message said that apc wasn't included in the buildpack. I need PHP 5.5 so I'm using php-buildpack#v4.3.2. Can you suggest a buildpack that includes APC?
I need an in-memory cache to replace Laravel's file cache. If I can't use APC, can anyone suggest anything else?
The Bluemix default PHP buildpack, which is listed in the admin catalog, is v4.1.5. This version supports both PHP 5.5 and APC. So you can bring your local environment to be compatible with PHP buildpack 4.1.5 to develop app on this version of buildpack.
PHP 5.5 and later come bundled with the OpCache, which supercedes the APC.
If you have code that uses the APC functions, you can continue using them in PHP 5.5 by using the APCu extension. APCu is APC, but with the opcache part removed (so that you can use the built-in OpCache instead), just leaving the memory cache and PHP functions to access it.
References:
http://jessesnet.com/development-notes/2014/php-55-opcache-apcu/
http://php.net/manual/en/migration55.new-features.php
http://php.net/manual/en/book.apcu.php
https://pecl.php.net/package/APCu
To close things out: I used php-buildpack#v4.1.5 which includes apc though it's based on PHP 5.4 so I had to down-level my guzzle to 5.3.0 which meant I needed to modify my guzzle code since I was using the guzzle 6 apis. I then changed my Laravel cache calls to use apc. Surprisingly, after all that the app still works, though whether it's really any faster is hard to tell

Is PHP Memcached fully backwards compatible with Memcache?

I am getting ready to upgrade a Debian server from PHP 5.6 to 7.0 via the dotdeb repositories. The Dotdeb repos do not have the (old) Memcache package, but they do have the (new) Memcached package. A third-party module I use relies on Memcache. Looking at the APIs, it appears that Memcached library should be fully backward compatible with Memcache, so that I can just do this:
if (!class_exists('Memcache') && class_exists('Memcached')) {
class Memcache extends Memcached
{
}
}
In testing it seems to work. The comments on the memcached documentation mention at least one gotcha, but since I am not looking to run them both at the same time, this one is not a problem.
However, I can't find anything else that talks about compatability. Is this a safe way to ensure backwards compatability between Memcached and Memcache or do I need a more sophisiticated adapter?
I'm not sure what has been going on with the PECL Memcache project, but the base Github project was updated to support PHP7, and yet remains unreleased in any official capacity (I need this as well so I've been keeping tabs on it).
A few weeks ago the Remi repo (CentOS/Fedora) published a PECL package based on these updates and it appears to be stable. If you are in need of this I would suggest you pull the Github repo and build the PECL extension. Without an official release it's the only thing I can suggest to you. This way you don't have to hack the older class to work with your existing code.
https://github.com/websupport-sk/pecl-memcache (unofficial)
https://github.com/php/pecl-caching-memcache (offical)
To answer my own question, no the two are not compatible. For anybody who may run into this issue, I wrote a small shim that replicates parts of the Memcache API and passes it through to Memcached. It is available for download on SourceForge.

Using APC in PHP 5.5

I want to functions like apc_store() and apc_fetch() in my PHP application (I never used APC before). However, my understanding is that APC cannot be installed on PHP 5.5+ because PHP 5.5+ has its own opcode cache. If I plan on upgrading to PHP 5.5+ in the future, should I use apc_* functions? If I shouldn't, are there "future safe" alternatives to APC?
As of 5.5 and onward I replaced on my setups APC with APCu. APCu is APC without the opcode caching. It also provides the apc_ functions and passes checks for extension_loaded('apc').
Make sure you use at least v4.0.2 of this extension. Prior releases had a bug in which the apc_ functions were not available even when the APC compat mode was turned on.
Also see the answers to this question.
The variable storage part of APC has been left in the APCU package. It's APC, without the code cache.

ZF2 PHP5.5 Cache Storage alternative for APC

I have been using ZF2 with PHP 5.3 and APC cache, and now I upgraded to PHP 5.5, and it seems there is no support for APC on PHP 5.5, I read that PHP5.5 have OpCache out of the box, but is it an alternative for APC? If yes How can I configure a Cache Storage Adapter for OpCache? if it is not to replace APC what can I use for PHP5.5? and how to configure an Adapter for it.
AFAIK OpCache differs from APC in that it's purely for caching scripts. You might want to take a look at the zf2 memcache adapter or hand roll your own with redis by implementing this interface. There are instructions here for implementing the interface, so it shouldn't be hard.
I use both memcache and redis extensively. I find memcache simpler but redis to have more functionality. If you only need a key-value store, i'd go with memcache as the adapter is pre-written.
Use the APCu like #ziollek's said. Starting from Php 5.5 Apc removed in favor of Opcache but APCu is a drop-in replacement for APC and it runs fully compatible with the good old APC.
So, Zend's APC cache storage adapter should work with APCu too.
See: https://github.com/krakjoe/apcu/issues/7

PHP: How to check and install mysqlnd_qc

I would like to use this plugin because can cache the query results. But even reading the docs at
http://dev.mysql.com/doc/refman/5.5/en/apis-php-mysqlnd-qc.setup.html
http://www.php.net/manual/en/mysqlnd-qc.setup.php
still confused. Does it mean it comes with PHP 5.4 by default? If not, how I can I check if it's installed from CentOS using a command line? Also, how can I check if it's installed on my local PC running XAMPP with PHP 5.4?
Thank you.
As far as I know, none of the mysqlnd plugins are installed by default.
I've tried installing one of the mysqlnd plugins (in my case it was mysqlnd_ms), but I've had limited success. I concluded that I needed to build both the mysqlnd plugin and PHP itself from source to get it to work.
At that point I lost interest, because none of my clients are willing to build PHP from source for their environments. They want to use binary installs, preferably from a yum package repo.
I don't think these plugins will catch on as viable tools until they are installable in a more convenient way, for example through PECL or Composer.
Okay, based on this doc, PHP 5.4 has installed MySQLnd by default
http://dev.mysql.com/downloads/connector/php-mysqlnd/
and to test it using this answer
How to know if MySQLnd is the active driver?

Categories