We are changing our hosting environment and they do not support apcu/xcache/wincache.
Currently we use apcu for Classloader cache in our Symfony PHP webapp as described here.
Because that component does not come with a MemcachedClassloader, does it even make sense to implement the Classloader cache in Memcached (non-distributed setup)?
As commented by COil and after reading the Symfony docs about performance I think we can just use the optimized flag for Composer autoload and tweak the settings for OPcache.
Related
I am using SilverStripe 4.2.2.
Wondering how could I configure Redis for caching in SilverStripe 4?
Take a look at pstaender/silverstripe-redis-cache which should make it a lot easier to get started with SilverStripe 4 and Redis right off the bat (since it implements CacheFactory and offers some configuration for SilverStripe). Also nice that it also uses predis, similar to Symfony's cache component noted above.
This happens to be ideal for me as well since one of my primary reasons for using Redis would be for template caching distributed across a cluster. 🙂
I am working on an application that was built in Zend framework 1. I want to install simpleSAMLphp as a service provider for it and trying to figure how best to do this.
I'm considering a couple of options:
Install it outside the application
(e.g. /var/www/myapp/simplesamlphp where my app's files are at /var/www/myapp/simplesamlphp). This is how it seems it's done in the installation tutorials. I guess this would work with some adjustments to the autoloading so it can pickup the SimpleSamlphp classes. I'm using composer to install dependencies so I can perhaps add the SimpleSAML folder to the class tree - not tried this yet. Or should I use the SimpleSAMLphp autoload file?
simplesamlphp-composer
I sees there is an option install with composer? So, if so, it will go within my application folder and files. However, I've tried this and not sure how to get composer to pick up the SimpleSAML classes. Anyone had much use of this method? I tried doing composer dump-autoload but it didn't add them. I guess I need to do more.
Can anyone give me some advice on how to use simpleSAMLphp with ZF1. Even just a point in the correct direction regarding where best to put files. We want to role this installation out to all our websites eventually so something that is easy to setup would be best I guess. I do like the composer approach but didn't have much luck with it. Previously the project used CAS with a phpCAS client - that was installed using composer which was quite convenient.
Any help would be much appreciated, thanks
I used ZF 1 and had following structure
/lib/Zend/ -- ZF
/lib/Zend.php
/lib/MyCompany/ -- my classes that supports ZF autolaod
/lib/ANyOtherZFCompatible
/lib/external/ -- any other libs that don't support ZF convention
I would put SimpleSAML into /lib/external/simpleSAML/
and at the beginning of your main file
require_once('/lib/external/simpleSAML/lib/_autoload.php'); and try to use init some SAML classes.
I'm using Symfony components in my web application. I need to store session in APC but unfortunatelly I can't find the way to do it.
As I see here Symfony does not support APC as a session handler. Is that true?
I have found an old example of using APC as a session handler in Symfony. But there all configuration is done in factories.yml file which I don't have since I'm only using standalone Symfony components.
Can anyone give me an example of using APC as a session handler using only Symfony components?
Since I don't get any answer here for a long time I will answer the question myself. For now there is no built in suport for APC as a session handler in Symphony framework. There is no particlar reason for it, likely Symphony developers just did not get to it.
The solution is simple, just code APCSessionHandler.php file yourself (I was not doing it because we decided not use this in project), APCSessionHandler will be very similar to MemcachedSessionHandler.php file.
How to store PHP sessions in APC Cache? suggests it is feasible but a bad idea for a busy site. The accepted answer lists a few useful ideas
My question is are the Symfony 2 cache mechanism and Twig cache mechanism the same?
Lets say I decide to use Twig in my MVC framework, would I have the same cache mechanism Symfony 2 uses? I know both Symfony2 and Twig are created by Fabien. But I dont know is Symfony 2 using only Twig cache or is there something more?
So I hope you understand the question. Does Symfony 2 uses Twig for cache? And if not, what are the differences between Symfony 2 and Twig caching?
unsure of the full answer, but symfony and twig must use separate caching mechanisms as you are not forced to use twig in symfony and yet cache still works. for more info check http://symfony.com/doc/current/ and dig into the code.
Edit:
To expand on my non-answer above. Twig cache is really a compilation cache. Your templates are saved as php files. To quote F. Potencier "[...] Twig caches the compiled templates to avoid the parsing phase for sub-sequent requests. [...]" (source)
While Symfony cache is (as has already been mentioned) a HTTP cache and is extensively explained in Symfony Docs cache section
Hope this helps.
Symfony 2 uses HTTP cache for caching purposes. And Twig cache is joust caching of Twig templates, so they don't have to recompile on every request. So Twig caching only ensures templates are compiled once on first request.
And Symfony 2 HTTP cache is another beast :) It provides abstraction around HTTP Cache mechanism and so you can cache using HTTP Cache headers etc...
So the short answer is NO! They are not the same!
No, they are not the same. Symfony caches a lot of stuff like routes, translations, the container, etc; Twig just caches templates by compiling them down to PHP classes. Of course, Twig's caching system works in a Symfony app as well.
I need to cache some application specific data using Symfony 2's caching system so that I can run cache:clear to clear it. All the cache relies under app/cache but how do I actually go about caching data?
http://symfony.com/doc/current/cookbook/index.html
The only topic I see is about HTML caching with Varnish.
If you are using Doctrine already just use those cache classes.
Add a service to config.yml:
services:
cache:
class: Doctrine\Common\Cache\ApcCache
And use it in your controller:
if ($fooString = $this->get('cache')->fetch('foo')) {
$foo = unserialize($fooString);
} else {
// do the work
$this->get('cache')->save('foo', serialize($foo));
}
Simple way use Doctrine cache providers.
At first, register service(sample in config.yml):
services:
memcached:
class: Memcached
calls:
- [ addServer, ['localhost', 11211] ]
memcached_cache:
class: Doctrine\Common\Cache\MemcachedCache
calls:
- [ setMemcached, [#memcached] ]
Then to use get service, for example in controler:
$cache = $this->get('memcached_cache');
to send in another service use calls:
calls:
- [ setCacheProvider, [#memcached_cache] ]
or arguments:
arguments:
- #memcached_cache
In the same way, you can use other interfaces of Doctrine Cache package.
Doctrine Cache provides a very simple interface for which several out of the box implementations are provided:
ApcCache (requires ext/apc)
ArrayCache (in memory, lifetime of the request)
FilesystemCache (not optimal for high concurrency)
MemcacheCache (requires ext/memcache)
MemcachedCache (requires ext/memcached)
PhpFileCache (not optimal for high concurrency)
RedisCache.php (requires ext/phpredis)
WinCacheCache.php (requires ext/wincache)
XcacheCache.php (requires ext/xcache)
ZendDataCache.php (requires Zend Server Platform)
If you do not already use Doctrine, you may require Common Library for Doctrine projects: php composer.phar require doctrine/common or require only Caching library offering an object-oriented API for many cache backends: php composer.phar require doctrine/cache
How to use Doctrine Caching you can read in Doctrine Common documentation on Doctrine Project web site
Symfony 3.1 provide a new Cache component.
Symfony2 does not provide any component for application layer caching.
Like you were already told, you can use the Doctrine Common caching library http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/caching.html
If you want something more advanced, you can also use one of the cache bundle provided by the community. For instance, the https://github.com/TheBigBrainsCompany/TbbcCacheBundle#cachebundle which provides tools for a good caching strategy.
There is no partial cache in Symfony2, the build-in cache is full HTTP only.
You have to use a reverse proxy, and if you only want to cache a piece of code, you have to use ESI. It's maybe more work than with symfony 1 but performances worth it.
Anyway, nothing stop you to use a memcached and store some stuff in it, look at this Bundle i.e.
If as your question state it, you only have data to store, that's perfect (and a memcache cache is much faster than a filesystem one).