Skip to content

Conversation

@kalfheim
Copy link

@kalfheim kalfheim commented Jun 4, 2016

Recently, ngrok announced multiregion service to general availability, which allow users to change to a datacenter region closer to themselves.

The default region is the US, which may cause a high response time for developers in other regions. I live in Norway, and I'm getting around 400 to 500 ms response times according to the Chrome Devtools when using the default us region. When switching to the eu region, the response times drop to around 100 ms. A huge improvement!

This PR allows you to run the following command:

valet share <region-code>

# For example...
valet share eu

I'm not sure if I love this approach, but you may think of this as a proof of concept. Maybe some bash master could improve the code? I'm definitely open for suggestions.

Perhaps adding a new command like valet region eu - which would set the region in some config file - would be better? This way you won't have to specify the region every time you want to share the site.

Currently, the following regions are supported by ngrok:

  • Default: United States (us)
  • Europe (eu)
  • Asia Pacific (ap)
  • Australia (au)

Try it out:

~/.composer/vendor/laravel/valet/bin/ngrok http -host-header=rewrite -region=eu "site-name.dev:80"

Replace site-name with your project's directory name. If you're not using the default .dev domain, then replace that too.

@kalfheim
Copy link
Author

This is obviously not gonna get merged as is. 😭

Any suggestions as to how we could implement this feature differently?

fi
done

# Determine which region to pass along to ngrok...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be REGION=${2:-"us"}, which will take the second argument as the region, using us as the default value.

@michaeldyrynda
Copy link

michaeldyrynda commented Jul 12, 2016

I was just going to submit a PR for the same thing. My approach just removed the if statement (we know how much @adamwathan hates those), which I've commented on your PR.

I looked at adding the value to the valet config file, but as the share command operates outside the rest of valet, it means there'd be some calls to PHP to fetch the config, and there's not really an easy way to parse the JSON without external dependencies.

Would love to see this merged in, US adds a few too many milliseconds for us Aussies.

@kalfheim
Copy link
Author

kalfheim commented Jul 13, 2016

Hm.

We could add a new valet region [region] command for getting and setting the region, similar to the valet domain [domain] command.

Then we could fetch the region by doing REGION=$(php "$DIR/cli/valet.php" region) in the valet file.

This would make it easy for the developer to set the region by running valet region eu.

Thoughts? @taylorotwell @adamwathan

We could also extend this to auto detect the most appropriate region for the user during the valet install process by looking up the IP address (using some third party API?). Might be a bit overkill, but it's just a quick idea.

Edit: Or by pinging each region a few times to find the fastest one.

@adamwathan
Copy link
Contributor

Hey thanks for the PR! I've opted to merge #112 instead as it's a simple one line change that also exposes any other ngrok options paid users might want.

@adamwathan adamwathan closed this Aug 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants