05.
debug:container & Cache Config
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
39 Comments
Hi guys!
I didn't found an answer here how to install APCu on Mac so I want to write my own instruction.
So first you need to have a <a href="https://brew.sh">brew</a>.
If you have PECL, you can go to the next step; if not, you should update PHP
brew install phpThen you should install APCu with PECL
pecl install apcuAfter that open your php.ini and add these line to the end of file
<br />[apcu]<br />extension=php_apcu.dll<br />apc.enabled=1<br />apc.shm_size=32M<br />apc.ttl=7200<br />apc.enable_cli=1<br />apc.serializer=php<br />Tadaaaaam! 🎉
Everything works as expected 💪🏻
Awesome! Thanks for sharing it Mikhail G.
Hi everyone,
In order to install APCu inside Linux, you must run:
Best regards
Or
$ sudo yum install php-pecl-apcu
And don't forget to restart the web server
Hey Alar
Thank you for this tip when you have Yum package manager instead of Apt!
Cheers!
Hey Abelardo,
Thank you for sharing this with others!
Cheers!
Speaking about performance, do you recommend to install the PECL YAML PHP Extension? Ive heard that it can parse up to 5x faster .YAML files than symfony itself.
Hey Mike P.!
Ah, VERY good question & point! First, if you did install the YAML PECL extension, it wouldn't make any difference: internally, Symfony always uses its own parser (it isn't written to fallback to the PECL version if it's available). But, more importantly, YAML is ONLY parsed when the container is being built. And this happens only in 2 different scenarios:
1) During development, the container is rebuilt (and YAML is parsed) when refreshing after you've made some changes to your configuration files. So, it's not parsed on every request - only when needed.
2) On production, the container is rebuilt only ONE time, during your deploy phase, when you run the
bin/console cache:warmupcommand. Then, your YAML files are NEVER parsed again (you could even delete them!).So, the YAML parsing adds limited overhead during development and zero overhead during production. And even in development, I think you'd find that it is very little of your processing time (I've never benchmarked this, but I DO know that the code that takes up most of the time is PHP code that's independent of the YAML parsing).
tl;dr You can't install the PECL extension to speed things up... but you also don't need to even worry about it ;).
Cheers!
You are brilliant! Thanks
Hello Ryan, any reference to configure the app.cache using a redis cluster? Can I pass a snc_redis config as parameter?
Hey @rafix,
To configure app.cache to use Redis you need to tweak the config to:
Here's some docs about RedisAdaper: http://symfony.com/doc/3.4/components/cache/adapters/redis_adapter.html
FYI, here's related issue: https://github.com/snc/SncRedisBundle/issues/291
Cheers!
Hello :)
How can I use different cache adaptors in different scenarios? for example somewhere I prefer to use redis and somewhere else apcu? the only way is by creating custom pools or is there another options?
Hey Amin,
Yeah, you just need to create different cache pools. Then, Symfony will automatically register them for autowiring, see those new services in "bin/console debug:autowire" to know how to get them
Cheers!
Just installed APCU on windows, am I missing something or APCU is really slower than filesystem cache ?
Hey Lionel,
Well, it should not, but it relates to Windows OS probably :/ Looks like for you it's slower than filesystem cache, that's weird. Could you restart your computer and try again? I'd also recommend you to turn off your antivirus if it's possible, it may block/check requests and that's why it slows. Otherwise, I'd recommend you to try a different cache storage like Redis maybe if it's an option for you? Unfortunately, things might be tricky on Windows :/
Cheers!
Perhaps a silly question, but I don't fully understand when you want to clear Symfony's internal cache. Should you do this just once when you deploy your application? Or should you do it (also) every time you make changes to your application's code (a change to a controller or a twig-file for example)?
Hey Dirk
On production you have to clear the cache after doing almost any change, by running
bin/console cache:clearbut if you are on "dev" environment you don't have to manually run that command, Symfony is very smart at detecting when to clear the cache but sometimes you have to manually clear the "var/cache" folder, it's a rare situation but sometimes you have to do it.
Cheers!
Hello,
For information : Cache config is in the cache.yaml file (and no longer in the framework.yaml file).
Hey ojtouch!
You're right! For clarity, in new projects, the cache config now lives in config/packages/cache.yaml. We'll add a note to the tutorial to make sure other people don't get confused!
Thanks!
Does it mean that you only need to uncomment the "app: cache.adapter.apcu" line in cache.yaml ?
... cause, by doing all the previous setup, i got a CacheException alert telling me that APCu in not enabled
Hey Mathieu,
Sure, since you uncomment APCu cache adapter - you should have it installed and enabled so you can use it in your application. And that's great that you got a clear error message for it.
Cheers!
Hi guys, I have read all the comments but I can't seem to figure out how to enable the APCu when using the built in server of Symfony? Is this the moment I stop using the built in server and configure my own apache and php?
Hey Sarah V.
You should be able to enable APCu even for the Symfony's built-in web server but you have to install & enable it first on your computer. Probably this guide will help you: https://serverpilot.io/docs...
Cheers!
You're the best <3
Hi everyone,
If apcu is not installed onto your system...
https://stackoverflow.com/q...
Brs.
Hey Abelardo L.
Thanks for the info man!
Is APCu recommended for most projects (instead of choosing nothing)?
I have read on the internet: "All PHP packages now come pre-built with Zend OPcache by default, but you can still install APCu Cache as a data store." so does symfony performance improve with APCu instead of the default Zend OPcache?
Hey Mike,
Good question. APCu and OPcache are different things, as also APCu and APC are different things as well, because APCu is a *user* cache. If we're talking about legacy projects that does not have OPcache, then installing APC will improve performance, but if your PHP version already have OPcache - you don't need neither APC nor APCu, OPcache is enought. However, APCu can be used for cache other things, but it require some configuration.
Btw, this article may be interesting for you: https://symfony.com/doc/cur...
Cheers!
It would be nice to have a docker-compose installation in order to don't have to install APCu locally or struggle with its installation.
Hey Luis,
Yes, agree, that would be cool, but it would be harder to maintain this code for us. And to be honest, Docker deserves a separate topic and not all our users may know and use this technology.
Cheers!
Hello,
I tried to code along but got stuck when I activated APCu in framework.yaml. When I refreshed the page, I got a CacheException and the following message: "APCu is not enabled". Of course, I watched the video in its entirety and know that I have to download the APCu PHP extension but after looking for a solution to do so, the only resource I found was this website: https://guides.wp-bullet.co... It concerns Wordpress, so I was wondering it this method is a good way to install APCu within the scope of this course, or do you suggest me another way?
Thanks.
For those on Ubuntu 16.04 (or probably other Debian flavors) and using PHP 7.2, I ran the console command:
I then had to restart my server to get it to kick in:
Hey Chris,
Thanks for sharing it! Anyway, after successful installation of new PHP extensions just do not forget to restart your web server. And btw, you also need to restart PHP-FPM if you use a real web server like Nginx or Apache along with PHP-FPM.
Cheers!
Hey Ajie62
If you managed to install APCu, maybe you just need to enable it, you have to add "extension=apcu.so" to your php.ini file (if you are on Windows I believe it should be "extension=apcu.dll", after that, restart your web server and everything should be ok.
Cheers!
Hi MolloKhan
Unfortunately, I didn't even manage to install APCu. I'm on a Macbook Air.
Oh, well, I more a linux/windows user, but I just found a post that may guide you in the right direction. Open this link: https://getgrav.org/blog/ma... and scroll down to the section "Install OPcache and APCu"
I hope it helps you. Cheers!
Hi,
I'm struggling to install APCu PHP extension on Windows. How should it be done?
I've found the answer here: https://stackoverflow.com/q...
Hey Daniel,
Great! And thanks for sharing it with other Windows users!
Cheers!
"Houston: no signs of life"
Start the conversation!