Using APC in PHP 5.5 - php

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.

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

Opcache equivalent function to apc store

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.

Will APC appear in PHP7?

I read all over internet that APC will be included in PHP6. However the PHP6 project was cancelled and they skipped one major version to avoid confusion, which then again causes more confusion. This however is another discussion for another time.
My question is:
Will APC or any other cache module still be introduced, included and enabled by default in PHP7?
The reason why I am asking is because I am considering implementing memcached into my projects. But if there is a native cache solution in PHP7 i'd rather stick to that.
PHP 7 has a built-in opcache, APC is deprecated and will not work.
Enabling PHP7 Opcache
Reference: http://php.net/manual/en/intro.opcache.php
PECL Extension: # https://pecl.php.net/package/ZendOpcache

Switching from APC to APCu

I am running a web server with Debian and I'm hosting a ZF1 project.
The PHP process crashes from time to time without any reason, so my hosting provider suggests that I should switch from APC to APCu caching. I'm not very familiar with PHP caching and I can't really find any documentation on the topic, but I read a few similar questions here.
As far as I understand the APCu caches only user data (whatever that means) and it's not the full features of the APC. Considering this, my question is will APCu increase the load of the server and will the PHP extension work out of the box without touching the ZF1 code?
http://zend-framework-community.634137.n4.nabble.com/Does-ZF-1-12-support-PHP-5-5-td4661902.html
You should upgrade to the latest PHP on a test environment, if it works well (most likely scenario), you can switch. PHP 5.5 has built-in opcode cache (http://php.net/manual/en/intro.opcache.php), so you won't lose performance. Very little difference can be between the performance of APCu and APC.
Also, function names are not identical (apcu_fetch for instance), so you have to modify the code to reflect this.

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

Categories