简体   繁体   中英

Symfony 2 Different behaviors between prod and dev environments

Context : I have been asked today to add a new feature on a quite old project (something like Symfony 2.0). It consisted in adding a new attribute to an entity and add the corresponding field to the edition form. Child play : I have edited the code and it works well in dev environment (set directly in app.php)

Problem : When the environment set in app.php is prod , the entity is not persisted when the form is submitted, nor retrieved when the form is loaded.

Investigations : What I have checked so far in prod env :

  • The submitted form is correct
  • The controller manages to map the form and to hydrate the entity correctly
  • I have deleted the cache multiple times both manually and from command line
  • I have checked the SQL query after the form has been submitted, the query does not update my new field as expected

Supposition : The problem seems to apppear when the entity is flushed, it is like the new field was completely ignored.

Assumption : After having exposed my problem to more experienced symfony developers, the only suggestion was that there may be a PHP cache (not the symfony one) somewhere parasitizing my prod env. This assumption is being tested (I could not restart apache myself) and I will be able to test it maybe tomorrow in the best scenario.

Still, I feel like the PHP cache assumption has 10% chance to be the good one. I can not share with you the whole project code, but I am asking you if you could post every idea you might have regarding this issue.

UPDATE : I have restarted Apache2. Problem is still persisting. It seems like Doctrine builds its cache on a former version of the project (It does not see any changes in the annotations for example) even though app/cache/ is empty. Any idea ?

I have deleted the cache multiple times both manually and from command line

Can you clarify? Symfony's cache is not the same as doctrine's. Depending on your configuration doctrine could be using something like apc, reddis or something else to cache its own queries and result data. If you haven't yet, try to perform these commands:

app/console doctrine:cache:clear-metadata 
app/console doctrine:cache:clear-query  
app/console doctrine:cache:clear-result 

If you're still out of luck, I'm more than 10% sure that an apache restart will do the trick.

If this worked, you should check your prods config yml and see if you find something like:

metadata_cache_driver : something
result_cache_driver : something
query_cache_driver : something

Full answer was to execute :

app/console doctrine:cache:clear-metadata --env=prod

The caching was caused by a memcache configuration only present in production environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM