If you are running an Yii-app on Appfog with mulitple instances, and you are using CAssetsManager for your static files, you will (at least I did) experience issues with broken links to static files.
I concluded that the reason is that each instance on AppFog will have a different paths to each asset. Here's an example.
Instance 1: /mnt/var/vcap.local/dea/apps/54dc7546ac14/app/protected/assets/logo.png
Instance 2: /mnt/var/vcap.local/dea/apps/54dc7546ac14/app/protected/assets/logo.png
Instance 3: /mnt/var/vcap.local/dea/apps/54dc7546ac14/app/protected/assets/logo.png
When Yii publishes these assets they will get different paths, since each path is based on a hash that is based on dirname()
returned by the function generatePath(). I know about the option hashByName
, but setting it to true will share the published path among different extensions.
Therefore the public path to the logo.png
will have three different possibilities:
Instance 1: https://www.example.com/assets/fb4gf4ac45/logo.png
Instance 2: https://www.example.com/assets/ab4ed4f394/logo.png
Instance 3: https://www.example.com/assets/fde07233bc/logo.png
The implication will be that when requesting www.example.com a arbitary instance will handle the request. Let's say it is instance 1, which will give a response with a link that refers to https://www.example.com/assets/fb4gf4ac45/logo.png
. The link will trigger a second request, and this time another arbitary instance will handle the request (instance 2).
The problem is that the instance 2 cannot find assets/fb4gf4ac45/logo.png
, since the file on this instance is located at assets/ab4ed4f394/logo.png
.
This can be handled by using the S3AssetsManager, but it will still upload assets for each instance to S3, and that makes the site slow every time the codebase is updated. It also results in A LOT OF assets paths on S3.
THE QUESTION:
So, even though I do have a work around I wonder if there is a better way to handle multiple instances on Appfog without changing the Yii-source code.