I deployed my php code to an app engine. Because of load balancing, requests sent to the app engine are automatically distributed to different servers. Since the assets folders on different servers are created automatically by Yii and their names are random and different, this causes asset folder mismatch problem. For example,
There is a page request, after load balancing it goes to SERVER_1, and the corresponding jquery folder is /assets/aaaaaa/jquery.js;
Then the browser send request to get the javascript file. However, this time the request goes to SERVER_2 after load balancing, but the file /assets/aaaaaa/jquery.js does not exist on SERVER_2 (for example, it might be /assets/bbbbbb/jquery.js).
Now I temporarily solved this problem by using URL write that redirects all requests sent to /assets/[random_number]/ to a static folder /assets/static/. I think this is not a good solution due to its lack of flexibility.
Is there any way to avoid this problem? Many thanks.
Has anybody found a proper solution for this problem? I’m facing the same issue.
My idea was to extend CAssetManager and overwrite the hash function.
/**
* Generate a CRC32 hash for the directory path. Collisions are higher
* than MD5 but generates a much smaller hash string.
* @param string $path string to be hashed.
* @return string hashed string.
*/
protected function hash($path)
{
return sprintf('%x',crc32($path.Yii::getVersion()));
}
Here $path takes the absolute server path - if we adapt the path to just use the relative path without server information, we could share the assets folder among different servers.