Yii Framework Forum: How To Keep Assets Folders Synchronized On Different Machines? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Keep Assets Folders Synchronized On Different Machines? Rate Topic: -----

#1 User is offline   williamhu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 29-July 11

Posted 10 January 2013 - 12:20 PM

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,

1. There is a page request, after load balancing it goes to SERVER_1, and the corresponding jquery folder is /assets/aaaaaa/jquery.js;
2. 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.
0

#2 User is offline   deretou 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-February 13

Posted 05 February 2013 - 03:53 PM

I have the same problem. I use Yii whith nodejs, mongodb on CentOS VMs.
0

#3 User is offline   jodev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 10-January 11
  • Location:The Netherlands

Posted 06 February 2013 - 06:55 AM

Just brainstorming here, but wouldn't it be possible to extend CAssetManager, override generatePath and then class map the new class to CAssetManager?
0

#4 User is offline   Idan Hen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 27-October 12
  • Location:Israel

Posted 23 April 2013 - 03:27 AM

Hey ,

i have the same problem.
i am using load balancer with yii behind. what is the best solution ? rewrite the AssetManger ?

yii is not supporting a load balancer use ? really ? :(
0

#5 User is offline   Mantas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 15-April 12

Posted 30 April 2013 - 06:59 AM

One of the workarounds is to use Sticky sessions in load balancer.
Another workaround would be to use CDN for your assets.
0

#6 User is offline   rooney10 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 29-August 12

Posted 30 August 2013 - 02:59 AM

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.

What do you think?
0

#7 User is offline   Idan Hen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 27-October 12
  • Location:Israel

Posted 17 October 2013 - 01:54 AM

Hi,

my solution was to leave the assets , and use CDN.
cloudFront/ cloudFlare , you pick it.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users