(轉)解決 Windows 系統使用 Homestead 運行 Laravel 本地項目響應緩慢問題

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

注意: 此方法可能帶來未知反作用,請操做以前務必備份原配置文件!!web

使用 win7 電腦學習第二本教程,發現項目運行起來切換頁面每次都要 7-10 s,很不正常啊,部署到服務器發現加載僅須要 200 ms 左右。shell

file

嘗試過增長虛擬機配置,可是沒有任何效果,通過驗證也不是數據庫的緣由,經過網上查詢瞭解到,是由於 VirtualBox 的 IO 引發的。數據庫

解決方案是安裝 NFS Plugin參考文章(英文)windows

英文很差的小夥伴接着看~服務器

首先,命令行進入 Homestead 啓動 vagrant學習

> cd ~/Homestead && vagrant up

而後運行安裝命令命令行

$ vagrant plugin install vagrant-winnfsd

file

如上圖,安裝成功後修改配置文件vagrant

修改配置文件前建議先備份,以避免修改後出現問題!code

文件 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 使配置文件生效,大功告成。再次運行項目響應時間已經正常了,但願幫助有相同狀況的小夥伴!

相關文章
相關標籤/搜索