Symfony2 and Twig performance in a vagrant box

喜你入骨 提交于 2019-11-29 07:53:16

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:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!