I am using Symfony2. I have a config.yml with users setting. In my development environment, if I change the list of users and refresh the browser, I see the change immediately. In production, I do not see the change, even though I have tried clearing the cache. What do I need to do to see the configuration change in production?
Try to clear the production cache with this command :
php app/console cache:clear --env=prod --no-debug
It it doesn't work, clear the content of the cache folder.
Related
I have bee using Symfony for a while now, and recently ran into an issue where the app/console cache:clear didn't want to clear the cache.
I then discovered that you can manually remove the app/cache directory to clear the cache.
So aside from doing the app/cache folder, what does cache:clear actually do? Why would i keep using it rather than removing the cache folder?
It also does the cache warmup (at least in version 3.1, which I'm currently using) unless you tell it not to do so with --no-warmup.
It's also easier and faster to run commands in IDEs like PHPStorm then manually doing things such as removing files.
Basically you can just remove cache directory if you prefer such way. Cache warmup will be performed at first Symfony request is needed.
You can also attach event to clear some of your custom cache.
This mean if you remove cache directory, you're not sure to clear custom cache handling
I have a website in Symfony linked to a a MySQL database. The website is having some troubles, so I have to update the information in the database. The thing is, when I update on the database, it stays updated there but on the website it doesn't show any changes.
For example, a user is registered. I go to the database to change the email so I can register another account with the same email. The database is updated with the new email, but on the website it says that the old email is still in use.
I know that I am updating the right database, because when I register a new client on the website, it appears on the database. Any ideas on to why this might be happening?
Like Angel Iliikov mentions in the comments, it's very likely a caching issue. The following suggestions assumes you have access to the command line - which a typical Symfony user should. If you don't already have it, most hosting providers allow you to get SSH access.
Clear the following caches:
1. Symfony's cache
Symfony will store a lot of data in the cache files to prevent it from having to process requests from scratch. When Symfony apps go wonky, a very common fix is to clear this cache and retry. The standard way to clear this cache is with a console command run at your project's root directory:
$ app/console cache:clear
If you run into issues, David Soussan answer provides more information on this one.
2. Doctrine's cache
According to commenters on another question (formatted by me):
The doctrine cache is often stored in apc rather than in the file
system so removing the cache files would not help. The general app/console cache:clear is only for the symfony (app) cache. I don't think it clears the doctrine cache(s).
-caponica
Alternative PHP Cache (APC) is an optional component enabled in php.ini. It's possible Doctrine is caching information there as well if it happens to be enabled.
The accepted answer on the previously mentioned question provides an answer for clearing Doctrine's cache:
$ app/console doctrine:cache:clear-metadata
$ app/console doctrine:cache:clear-query
$ app/console doctrine:cache:clear-result
-amitchhajer
3. Your browser's cache
This is very unlikely to be causing any issues. But if you are doing something to send caching headers over HTTP - it's possible that the application would have properly updated the data, but your browser is displaying an old page.
Each browser has a different way of clearing cache. Google provides support for how to do it Chrome. and Mozilla provides support for how do it in Firefox.
If clearing the cache doesn't solve your problem, it's likely a problem with your application or workflow and will need debugging. A few things you can try:
Make sure you really updated the correct database. Confirm this
on two separate DB clients.
Create your own Symfony
command
where the only thing you do is query the database. If it returns the correct result, you should check that other components are using the same query. If not, check your config/parameters to ensure you're using the right database.
If your Symfony application is not showing the updated database record that is because it is using the cache which still contains the old data. This is often a problem with Symfony, refreshing the page just reloads from the cache. Try clearing the cache first. Now, very often cache:clear does not work from the command line, I've had it happen all the time and never really understood why. The answer is to just delete all the cache files, as per Fabien Potencier's tip: http://fabien.potencier.org/a-symfony-tip-clear-the-cache-without-the-command-line.html. That works and is my go-to solution for when eg; composer update did not clear the cache afterwards. In fact I got into the habit of just deleting the cache files on my dev machine before doing composer install or update.
Adam,
Use these commands to clear your cache:
# dev environment
$ app/console cache:clear
# production environment
$ app/console cache:clear --env=prod
I had problems using the mysql database supplied by my host server at first but then I installed the latest mysql database version available in softaculus inside my host server and then I was able to access mysql inside softaculus or directly by the url (www.mypage.com/mysql). Finally it works perfectly. You can try to do something similar.
I have worked with one project on Symfony2. It works on my local server, but when I uploaded this project to the hosting, it has stopped working. Over time I have found, that problem is with the cache directory.
So uploading the cache from the local server to the hosting has solved this problem.
What can the problem be? What are the main problems with cache on Symfony2?
You don't upload the cache folder. These are only temporary files. Look at the docs about how to deploy.
Most likely you have to run:
php app/console cache:clear --env=prod --no-debug
Also check that the cache and log folder is writable as pointed out on the installation documentation:
I tried some solutions (ex: Transfer Symfony2 site onto localhost from web server), but never works, the result is always a blank page.
The project is on Symfony 2.3 and my php version is 5.5
Thanks
When accessing a Symfony2 site locally you need reference one of the routing files in the web folder directly. So try http://localhost/app_dev.php/ and it might give you an error message telling you what is going wrong. Also you can check the log files in the /app/logs folder to see what the problem might be.
Edit:
There are also several command line tools that might be needed to set up the project.
app/console doctrine:schema:update --force
This will check the database is in sync with your code and update the database if necessary.
app/console assetic:dump
app/console assets:install
app/console cache:clear
These are used to install css, javascript and other static assets as well as clearing the cache.
So I disabled my site with
symfony project:disable --env=prod
And rsynced my new code to the server.
But now when I run
symfony doctrine:migrate --env=prod
I get a warning that the site is currently unavailable.
I clearly don't want to enable the project (yet) as I first want to make it all works. What is the correct way to do this?
You are right. This doesn't work by default. If your production database is available from your development machine you can start the migration on this machine via:
$> php symfony doctrine:migrate --env=prod
Thats what I do in my deployment scripts
I would probably restrict access to your IP address in the index.php, such as when working in the dev environment. Enable the project and then run again.