I just started using Laravel. I've barely written any code yet, but my pages are taking nearly a second to load!

laravel timings

This is a bit shocking to me when my framework-less apps and NodeJS apps take ~2ms. What's Laravel doing? This isn't normal behaviour is it? Does it need some fine-tuning?

推荐答案

拉威尔的速度实际上是that慢.500-not0毫秒是荒谬的;在调试模式下,我把时间降到了20毫秒.

The problem was Vagrant/VirtualBox + shared folders. I didn't realize they incurred such a performance hit. I guess because Laravel has so many dependencies (loads ~280 files) and each of those file reads is slow, it adds up really quick.

kreeves pointed me in the right direction, this blog post describes a new feature in Vagrant 1.5 that lets you rsync your files into the VM rather than using a shared folder.

Windows上没有本机rsync客户端,因此您必须使用cygwin.安装它,并确保选中net/rsync.将C:\cygwin64\bin添加到您的路径中.[或者您可以将其安装在Win10/Bash上]

我用的是Puphet所以我的流浪者档案看起来有点搞笑.我不得不把它改成这样:

  data['vm']['synced_folder'].each do |i, folder|
    if folder['source'] != '' && folder['target'] != '' && folder['id'] != ''
      config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", 
        id: "#{folder['id']}", 
        type: "rsync",
        rsync__auto: "true",
        rsync__exclude: ".hg/"
    end
  end

Once you're all set up, try vagrant up. If everything goes smoothly your machine should boot up and it should copy all the files over. You'll need to run vagrant rsync-auto in a terminal to keep the files up to date. You'll pay a little bit in latency, but for 30x faster page loads, it's worth it!


如果你使用的是PhpStorm,它的自动上传功能甚至比rsync更好.PhpStorm创建了很多临时文件,这可能会让文件观察者感到困惑,但是如果你让它自己处理上传,它会很好地工作.


One more option is to use lsyncd. I've had great success using this on Ubuntu host -> FreeBSD guest. I haven't tried it on a Windows host yet.

Laravel相关问答推荐

我是否需要/是否可以从控制器运行LARLAVEL备份?

Laravel Eloquent查询与集合优化

Laravel 语法 GroupBy 获取列到数组

Laravel:在行的子集上同步多对多

如何避免谷歌翻译翻译:参数

Laravel Livewire 组件属性在 div 类中为空

mysql 加入 ON 和 AND 到 laravel eloquent

Laravel 4:处理种子中的关系

laravel 中的 Http Post 使用 fetch api 给出 TokenMismatchException

Laravel 中的合同和 PHP 中的接口有什么区别?

Laravel Blade 没有额外的空格?

Laravel 5.3 Electron邮件队列中不允许序列化关闭

Laravel 5:在同一字符串上使用 bcrypt 给出不同的值

如何将Carbon 转换为字符串,只取日期?

调用未定义的方法 Illuminate\Foundation\Application::bindShared()

Laravel 5 与 Postgresql

Eloquent - 更新集合中的所有模型

Laravel hasManyThrough

Laravel php artisan 产生错误

以编程方式而不是从 CLI 运行 Laravel 5 seeder