Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow File Uploads on virtual machine using virtualbox with vagrant + homestead

So i setup a virtual machine with vagrant using the virtual box container provided by laravel's homestead. (on my osx env)

I used the nfs option method of sharing my directories to my local environment and this speed up response times drastically. On a typical app, i'm getting like 20-40ms load per page. However, I noticed that file uploads are terribly slow. I can upload a 1MB file on a simple form that does nothing to the file and it will take about a 30seconds to a minute. Is this normal, or is there a way to speed things up even further besides using nfs shares.

like image 921
David Avatar asked Dec 15 '22 19:12

David


1 Answers

This has been driving me crazy for some time, and no amount of toying with Vagrant's or VirtualBox's settings (sendfile, NFS, adjusting packet sizes, etc.) helped. But with the help of this answer on a similar problem relating to failed image uploads, I've finally cracked it:

The key, for me, was changing my hosts file to resolve my Homestead domains to the homestead VM's IP of 192.168.10.10, rather than to 127.0.0.1. (When doing this, you also drop the port :8000 from the URL, so you just navigate to homestead.app).

This changed my file upload speed from around 25 KB/sec to 5980 KB/sec!

It appears that the Laravel docs were updated a week ago to reflect this change. I wonder if your Yosemite install coincided with the docs change, and you set up your new box with 192.168.10.10 while your old hosts setup pointed to 127.0.0.1.

Even though the Laravel docs have been corrected—so this issue shouldn't present itself for new Homestead installs—there are still a lot of tutorials floating around in the wild that suggest resolving Homestead domains to 127.0.0.1. Hopefully this answer will help head off some aggravation!

like image 188
damiani Avatar answered Feb 09 '23 00:02

damiani