Comments (8)
@goetas Yes I understood that. But by doing like @jaikdean is doing:
hateoas.configuration.metadata.cache.cache_warmer:
class: JMS\SerializerBundle\Cache\CacheWarmer
arguments:
$includePaths: ['%kernel.project_dir%/src/Entity']
$metadataFactory: '@hateoas.configuration.metadata_factory'
tags: [kernel.cache_warmer]
It does not take into account some classes present in the hateoas library. So I changed to:
# Cache Warmer Service for Hateoas. Necessary until:
hateoas.configuration.metadata.cache.cache_warmer:
class: JMS\SerializerBundle\Cache\CacheWarmer
arguments:
$includePaths: ['%kernel.project_dir%/src', '%kernel.project_dir%/vendor/willdurand/hateoas/src/Hateoas/Representation']
$metadataFactory: '@hateoas.configuration.metadata_factory'
tags: [kernel.cache_warmer]
But this still didn't do the trick while it did add the files in the var/cache/prod/hateoas directory.
I'm playing with this at the moment and what I just discovered is that it also needs to have those files in src/Hateoas/Representation for the JMS.
In conclusion I need to tell JMS warmup to also take into account src/Hateoas/Representation.
I will try that and let you guys know if it worked ... If it does ... wouldn't this be nice to have this configured in this bundle as per @jaikdean 's suggestion?
from bazingahateoasbundle.
Ok so that was the issue. The next configuration solves the issue and allows you to keep your cache folder read-only in production (assuming you don't have any other third party hitting the cache directory as mentioned by @jaikdean ):
config/jms_serializer.yaml
jms_serializer:
metadata:
warmup:
paths:
included:
- '%kernel.root_dir%'
- '%kernel.project_dir%/vendor/willdurand/hateoas/src/Hateoas/Representation'
What's important in the above snippet is the second include. The first one can be enhanced if you're files are more regrouped.
config/services.yaml
hateoas.configuration.metadata.cache.cache_warmer:
class: JMS\SerializerBundle\Cache\CacheWarmer
arguments:
$includePaths: ['%kernel.project_dir%/src', '%kernel.project_dir%/vendor/willdurand/hateoas/src/Hateoas/Representation']
$metadataFactory: '@hateoas.configuration.metadata_factory'
tags: [kernel.cache_warmer]
@goetas Wouldn't it be useful to have a part of this config in the bundle itself? Or at least have it documented?! (I'd be happy to provide a PR for both solutions)
from bazingahateoasbundle.
I agree that would be to have it. A pr (with tests) would be welcome!
from bazingahateoasbundle.
@jaikdean Do you confirm that if you really want your warmup to be 100% done you will also have to include the files inside the hateoas library? Otherwise in production, if cache is only readable it will fail because e.g. Hateoas-Representation-CollectionRepresentation.cache.php will not be generated.
EDIT: my first paragraph doesn't seem to solve the issue. Even by adding the generation of the classes in from hateoas vendor in production it stills fails because it cannot write into the cache:
It seems to want to save into the pool
[2018-12-18 13:00:33] cache.WARNING: Failed to save key "%5BHateoas%5CRepresentation%5CRouteAwareRepresentation%23__construct%5D%5B1%5D" (array) {"key":"%5BHateoas%5CRepresentation%5CRouteAwareRepresentation%23__construct%5D%5B1%5D","type":"array","exception":"[object] (ErrorException(code: 0): file_put_contents(/app/var/cache/prod/pools/hvoJTUZdSU/5c18ef714695b6.83591465): failed to open stream: Permission denied at /app/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:92)"} []
While I do have this in /var/cache/prod/hateoas/
4 -rw-r--r-- 1 root root 186 Dec 18 12:59 Hateoas-Representation-AbstractSegmentedRepresentation.cache.php
4 -rw-r--r-- 1 root root 493 Dec 18 12:59 Hateoas-Representation-CollectionRepresentation.cache.php
4 -rw-r--r-- 1 root root 181 Dec 18 12:59 Hateoas-Representation-Factory-PagerfantaFactory.cache.php
8 -rw-r--r-- 1 root root 5349 Dec 18 12:59 Hateoas-Representation-OffsetRepresentation.cache.php
8 -rw-r--r-- 1 root root 5206 Dec 18 12:59 Hateoas-Representation-PaginatedRepresentation.cache.php
4 -rw-r--r-- 1 root root 1183 Dec 18 12:59 Hateoas-Representation-RouteAwareRepresentation.cache.php
4 -rw-r--r-- 1 root root 489 Dec 18 12:59 Hateoas-Representation-VndErrorRepresentation.cache.php
And according the symfony's doc (https://symfony.com/doc/current/setup/file_permissions.html):
In the prod environment (i.e. when APP_ENV is prod and APP_DEBUG is 0), as long as you run php bin/console cache:warmup, no cache files will need to be written to disk at runtime.
@jaikdean Any ideas?
from bazingahateoasbundle.
@tonivdv Out of the box with Symfony, that quote from the documentation is true. However, third-party bundles might try to write there regardless of the env/debug settings.
I'm not sure about the issue you're having I'm afraid, I've not touched this since I opened the original issue, and the solution in my first post seems to work for us. We're probably only using a subset of the functionality in this bundle though.
from bazingahateoasbundle.
Can be done similarly as what implemented in schmittjoh/JMSSerializerBundle#615
from bazingahateoasbundle.
@jaikdean Ok. And also it depends if you made the /var/cache writable or not ... if writable then you don't "detect" this kind of issue
@goetas What do you mean with that? I currently took the snippet from @jaikdean which does warm the cache up, but still could the above error. Unless you mean something else with the reference?
Thanks
from bazingahateoasbundle.
@jaikdean is actually using the feature implemented in schmittjoh/JMSSerializerBundle#615
from bazingahateoasbundle.
Related Issues (20)
- New Tag for Symfony 6 HOT 1
- Symfony 7 support HOT 2
- Symfony 7: Service "annotation_reader" is no longer available HOT 2
- Release v1.1.2 HOT 3
- Implement PSR-13 HOT 2
- Incorrect version required in composer.json HOT 1
- Update dependency for jms/serializer-bundle HOT 1
- when will a new release be tagged? HOT 2
- Deprectation Notices in Symfony 3.3 HOT 2
- 500 ERROR HOT 1
- Change Symfony2 to Symfony in README.md HOT 1
- Twig extension loading configuration HOT 2
- Release 1.3.1 or 1.4.0 with latest changes HOT 4
- Xml Configuration HOT 1
- Override Groups Deeper Branches fails
- Why the ExtensionDriver is only enabled for annotation driver? HOT 1
- Symfony 5 HOT 2
- Enable Metadata\MetadataFactory::setIncludeInterfaces() HOT 2
- PHP8 support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bazingahateoasbundle.