Symfony2 and Twig performance in a vagrant box

后端 未结 2 1260
[愿得一人]
[愿得一人] 2020-12-18 08:42

Prerequisites:

  1. http://box.scotch.io/ vagrant box

  2. 2.
# -*- mode: ruby -         


        
相关标签:
2条回答
  • 2020-12-18 08:46

    In order to make it work faster in vagrant in case your host OS is Win (Windows 7 x64 in my case), you need to:

    1. add this fix. I also added 'prod' environment to the list:
    public function getCacheDir()
    {
        if (in_array($this->environment, array('dev', 'test', 'prod'))) {
            return '/dev/shm/project/cache/' .  $this->environment;
        }
    
        return parent::getCacheDir();
    }
    
    public function getLogDir()
    {
        if (in_array($this->environment, array('dev', 'test', 'prod'))) {
            return '/dev/shm/project/logs';
        }
    
        return parent::getLogDir();
    }
    
    1. Fix I/O performance by utilizing NFS. The thing is that I was confused: setting nfs=true option in synced_folders does NOT mean you're connecting through NFS. My host OS is Win7 and I had to install NFS server in order to make it work. Note that it's not free. Here are two folders I had to share:

    enter image description here

    Also, mounting with synced_folder did not work for me, as NFS server was only listening on specific IP address, so I had to comment out this:

    config.vm.synced_folder "../../../project", "/var/www", type: "nfs",:nfs => true
    

    and put this instead:

    $script = <<SCRIPT
      sudo mount 192.168.178.40:/d/project /var/www/ && sudo mount 192.168.178.40:/d/project/_conf /etc/apache2/sites-enabled && sudo service apache2 restart
    SCRIPT
    
      config.vm.provision "shell", inline: $script, privileged: false, run: "always"
    

    ,where 192.168.178.40 is the IP where NFS ports are open. You can scan it from yout gurest OS with, e.g. nmap.

    1. And you'll also need to install vagrant plugin called vagrant-winnfsd. It can be done by:

    vagrant plugin install vagrant-winnfsd

    0 讨论(0)
  • 2020-12-18 08:48

    I think it's not a problem with twig performance but directory sharing in VirtualBox/vagrant. Try to enable I/O caching in VirtualBox.

    0 讨论(0)
提交回复
热议问题