stevebauman / location

Retrieve a visitor's location from their IP address.
MIT License
1.13k stars 180 forks source link

Auto-download MaxMind MMDB files via an `install` command #117

Closed stevebauman closed 1 year ago

jamesmills commented 1 year ago

I was just thinking of submitting an idea similar and then found this open issue.

I've been using https://lyften.com/projects/laravel-geoip for a long time but someone recently recommended that I look at yours.

I thought I'd share a link to https://lyften.com/projects/laravel-geoip/doc/commands.html as they have a command that does something similar to what you're talking about here I think. I have this command run on every deployment to keep things updated. Could probably create a scheduled command to do something?

Just throwing this out there.

stevebauman commented 1 year ago

Hi @jamesmills!

This has actually been implemented in the v7.0 branch, but it hasn't been released yet:

https://github.com/stevebauman/location/blob/v7.0/src/Commands/Update.php

You will be able to schedule this command to keep the database file updated 👍

onlime commented 1 year ago

Hey @stevebauman - really interested in v7.0 with the Update command, which will finally make me switch from torann/geoip to your wonderful package. Are you going to release it soon? No pressure though!

stevebauman commented 1 year ago

Hi @onlime! Thanks for the reminder 😄. I've just released v7.0. Let me know if you encounter any issues during the upgrade process.

Closing this, as it is now completed, and updating the .mmdb file can now be done with the below artisan command:

php artisan location:update
onlime commented 1 year ago

Thanks a lot @stevebauman for this terrific package! 👏 I have just migrated from torann/geoip, enabled and scheduled updates for self-hosted MaxMind database. It works absolutely flawless and it was a super simple migration late night from the couch (usually I reserve such simple fun tasks for the toilet session).

jamesmills commented 1 year ago

Amazing work @stevebauman and thank you for the update.

@onlime excited to hear you managed the migration ok. Do you use the free MaxMind DB locally? How do you find it?

onlime commented 1 year ago

Hey @jamesmills

excited to hear you managed the migration ok. Do you use the free MaxMind DB locally? How do you find it?

I use the free MaxMind DB locally, planning to download it via daily scheduled location:update command. But currently, this is only for a project that goes live by the end of the year. I already have a production/staging deployment, so I can access it from various external IPs to test stevebauman/location and I think it's not quite production ready yet. Exception handling is too basic and hardcoded, especially in Drivers/MaxMind::process() where @stevebauman just uses the rescue() helper. I would rather like have the option (maybe by a config flag) to return some default position data (e.g. ['isoCode' => 'XX', 'countryName' => 'Unknown Country']) when IP was not found.

Currently, when accessing my site from some local IP (e.g. via VPN), I need to workaround with $position->isoCode ?? 'XX' and it would still raise the following exception, filling up my exception log and Sentry:

{
    "class": "GeoIp2\\Exception\\AddressNotFoundException",
    "message": "The address 10.10.0.2 is not in the database.",
    "code": 0,
    "file": "vendor/geoip2/geoip2/src/Database/Reader.php:260"
}

Also, Location::get() lookups won't work in my CI (GitLab CI) environment, as I don't want to download MaxMind DB there, so should probably override MAXMIND_WEB_ENABLED=true env var.

... but I should probably open a new issue for those issues and discuss there.