解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题(转)

原文:https://learnku.com/articles/9009/solve-the-slow-response-problem-of-windows-system-using-homestead-to-run-laravel-local-project

注意: 此方法可能带来未知副作用,请操作之前务必备份原配置文件!!

使用 win7 电脑学习第二本教程,发现项目运行起来切换页面每次都要 7-10 s,很不正常啊,部署到服务器发现加载仅需要 200 ms 左右。

file

尝试过增加虚拟机配置,但是没有任何效果,经过验证也不是数据库的原因,通过网上查询了解到,是因为 VirtualBox 的 IO 引起的。

解决方案是安装 NFS Plugin参考文章(英文)

英文不好的小伙伴接着看~

首先,命令行进入 Homestead 启动 vagrant

> cd ~/Homestead && vagrant up

然后运行安装命令

$ vagrant plugin install vagrant-winnfsd

file

如上图,安装成功后修改配置文件

修改配置文件前建议先备份,以免修改后出现问题!

文件 1:homestead/scripts/homestead.rb

# Register All Of The Configured Shared Folders
if settings.include? 'folders'
    settings["folders"].each do |folder|
        if File.exists? File.expand_path(folder["map"])
            mount_opts = []

            if (folder["type"] == "nfs")
                mount_opts = folder["mount_options"] ? folder["mount_options"] : ['actimeo=1', 'nolock']
            elsif (folder["type"] == "smb")
                mount_opts = folder["mount_options"] ? folder["mount_options"] : ['vers=3.02', 'mfsymlinks']
            end

            # For b/w compatibility keep separate 'mount_opts', but merge with options
            options = (folder["options"] || {}).merge({ mount_options: mount_opts })

            # Double-splat (**) operator only works with symbol keys, so convert
            options.keys.each{|k| options[k.to_sym] = options.delete(k) }

            config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil, **options

            # Bindfs support to fix shared folder (NFS) permission issue on Mac
            if Vagrant.has_plugin?("vagrant-bindfs")
                config.bindfs.bind_folder folder["to"], folder["to"]
            end
        else
            config.vm.provision "shell" do |s|
                s.inline = ">&2 echo \"Unable to mount one of your folders. Please check your folders in Homestead.yaml\""
            end
        end
    end
end

查找此段代码(可能略有不同),替换为以下内容

if settings.include? 'folders'
  settings["folders"].sort! { |a,b| a["map"].length <=> b["map"].length }

  settings["folders"].each do |folder|
    config.vm.synced_folder folder["map"], folder["to"], 
    id: folder["map"],
    :nfs => true,
    :mount_options => ['nolock,vers=3,udp,noatime']
  end
end

文件 2:Homestead.yaml

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: nfs
vagrant provision && vagrant reload
//更新配置并重启虚拟机

重启 Homestead 使配置文件生效,大功告成。再次运行项目响应时间已经正常了,希望帮助有相同情况的小伙伴!

转载于:https://www.cnblogs.com/mg007/p/11170087.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值