How should I do to clean up the symfony2 cache - symfony

I'm a website administrator,my site were build on symfony2 freamwork.
My site has a lot of users.When I clear the cache,a few users are accessing my website,so I can not quite put clean cache that caused a lot of problems.
How should I do to clean up the cache?

To clear the cache in symfony you need to execute the following command :
php app/console cache:clear --env=prod
the --env=prod tells the console to execute in the production environment. This will remove the previous cache.
Note:
By default Symfony will store session information in its cache directory. Clearing the cache will mean that every user has to re-authenticate.
You can change the path that Symfony uses to store the session files by changing the following line in the app/config/config.yml.
framework:
session:
save_path: %kernel.root_dir%/sessions
The save_path setting will then store session information inapp/sessions.

I had faced this problem multiple times. If your website was accessing by so many user and you clear the cache. i am sure your website was down for couple for minutes until the new cache generated.
So clear cache on production server should not be a regular activity.
There are couple of solution or tricks to overcome from this problem:
find the time when your website has low traffic. May be sometime in the night and then clear the cache.
When you want to clear a cache, setup a replica of a production server then plan to switch the public domain ip to the new replica for the timing so that user cant face the downtime and once you cleared the cache on a actually production server. switch the public domain ip back to the production server.
if you do some changes in the templates i.e.twig and wants to made changes live on the production.Then try to find the templates in the app/cache/prod/twig directory and grep the templates name and you will get the files. Than move the files or delete the files and yours changes will live on the production server.
how to clear the cache
php app/console cache:clear
chmod -R 777 app/cache
chmod -R 777 app/logs

Related

Browser closes after project's cache cleaned [symfony2]

I have a project in symfony 2.3.
I had to clean it's cache to free some space of my server. But after I didn't the browser doesn't even load the page as before. It goes to the link and after it closes without any response.
I don't know which informations are useful to this problem. I had just ran the command:
sudo php app/console cache:clear
Must I clean the cache for the prod environment too?
Is it dangerous to the project to clean the cache of the project? I always think that may crash the whole thing.
Thank you
You should check the permissions of the cache directory and also move your sessions in a separate folder, because a cache:clear also logout any logged user if you don't handle the sessions directory.
framework:
session:
# Don't forget creating the folder /var/sessions with the right permissions
save_path: %kernel.root_dir%/var/sessions

Put Assetic back in dynamic mode after assetic dump

I'm using Symfony2 and Assetic. Lately I've been doing a lot of CSS work so at a certain point I needed the command
$ php app/console assetic:dump --env=prod --no-debug
Ever since I've used it I need to run that command everytime I change CSS to see the difference. Now I've did some research and found out that I can put Assetic in to watch mode so I don't have to run the command above after every change using the following command:
$ php app/console assetic:dump --watch --env=prod
However, I just want it back to before I put it into this manual mode. The Symfony2 documentation explains how to do an assetic dump, but not how to put it back in dynamic mode (http://symfony.com/doc/current/cookbook/assetic/asset_management.html#dumping-asset-files)
Does anyone know how to put it back in dynamic mode?
There are two likely possibilities for Symfony not dynamically serving assets from the internal controller:
1. assetic.use_controller is not really true
Confirm 100% you are telling Symfony assetic.use_controller is true. One straightforward method of debugging would be adding this to the top of your controller action and reloading the page:
var_dump($this->container->getParameter('assetic.use_controller'));die();
Not getting true as a return value could mean you are overriding use_controller in either config_dev.php or config_prod.php depending on what environment you are pointing at.
2. Your web server is checking for static assets before passing to Symfony
Most webservers can be configured to check if a URL points to a physical file asset and deliver that file. So if you have dumped assets in Symfony, the webserver might be serving that file and not passing the request onto Symfony.
For nginx see: http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
For apache see: Apache rewrite rule similar to Nginx try_files
The solution would be to remove the dumped asset files from the file system. Their location depends on where you configured them to go, but check in web/js, web/bundles, etc.

openshift wordpress plugin needs to be granted write access, how do this?

I am trying to install CiviCRM in my openshift wordpress 'gear' And I am getting the following when I attempt to run civicrm's installation wizard:
The user account used by your web-server - 542ddc2950044666c40008d9 -
needs to be granted write access to the following directory in order
to configure the CiviCRM settings file:
//var/lib/openshift/542ddc2950044666c40008d9/app-root/data/plugins/files
Does anyone know if what it is asking is possible?
and then how do I go about setting that?
Thanks!
The plugins/files/civicrm directory is where CiviCRM stores its cached templates, file attachments, premium (thank-you gift) images, and more. It'll need to save stuff there regularly, not just at first.
The best thing to do is to log in through SSH like developercorey recommends and:
cd ~/app-root/plugins
chmod 755 files (changing the permissions so the owner can write and everyone can read/execute)
chown 542ddc2950044666c40008d9:542ddc2950044666c40008d9 files (making the user that the web server runs as ("542ddc2950044666c40008d9" as mentioned in the error message) be the owner of the directory
have the installer check again
SSH into your gear using the rhc ssh command
cd ~/app-root/plugins
ls -lah
Look for the "files" directory and see what the user and the permissions are on that folder, you can change with the "chmod" command to allow it to be written to by the web server, but be careful what you do or you could cause a major headache for yourself (like getting your WP blog hacked). Hopefully the instructions for that plugin include setting the permissions to something reasonable when you are done.

Symfony2 login fails when session.storage.filesystem is set for storage_id

I'm trying to do some functional testing with PHPUnit but it requires that I add session.storage.filesystem for the storage_id option in config.yml.
This causes the login process to fail, for some reason. I get the following error in test.log :
Authentication request failed: Your session has timed-out, or you have disabled cookies.
Afterwards I'm redirected to the login page again. I'm certain that I have cookies enabled and that the application works without setting that option(with native session storage).
Could anyone tell me whether there is any solution for this issue?
Give a try at changing your file permissions for the cache folder. If they're not set properly , this is what will happen:
You develop stuff and test it through your web browser => your apache (or other server) will create the cache and will be the only one to have permissions on it
You start phpunit tests from the command line (different unix user) => the current unix user does not have write access to your cache folder and cannot store the sessions.
Immediate fix to validate that this is the case:
chmod -R 777 app/cache/
phpunit -c app/
If this is actually the case, then go check how to properly set the rights at: http://symfony.com/doc/current/book/installation.html#configuration-and-setup

Symfony2 presents rendering different views in dev and prod environment

I designing an programming a website using Symfony2. I completed some parts and checked the client side in both dev and prod environment. In the first time everything was fine and I saw same result in both environments, But after sum changes in views (I'm using Twig with Three-level Inheritance) such as adding sum other stylesheets in "stylesheets" block, dev environment works fine but in prod environment no stylesheets added and its using old data. I cleared cache and log manually from both path "app/cache/dev" and "app/cache/prod" ... but nothing changed. I removed all stylesheets in block and cleared chache again old data is still there!
Any suggestion?
Apart from clearing the cache, make sure you publish your assets:
app/console assets:install --symlink web
app/console assetic:dump
The problem was about removing cache files. I had been removing cache files via cPanel filemanager. It gave "all files removed successfully" but they didn't. So I found another way to clear cache. I used shell_exec:
shell_exec('rm -r app/cache/prod');

Resources