Product Decisions This Supports
- China-first geo-personalization. Resolves visitor IP to country/province/city plus ISP (电信/联通/移动) using the QQWry/纯真 dataset, which is what enables decisions like "show RMB pricing," "default to 简体中文," "surface 江浙沪 shipping estimates," or "route to the 上海 region."
- Build vs. buy for IP intelligence. This package is the build-nothing / buy-nothing option: no per-lookup API fee, no vendor contract, no key rotation. It converts an ongoing usage cost into a one-time integration plus an ongoing data-refresh chore. That trade is attractive at low-to-moderate volume and unattractive if you need a vendor SLA.
- Data residency and compliance posture. Because lookups run entirely in-process against a local binary file, raw user IPs never leave your infrastructure. For teams scoping work under PIPL / Cybersecurity Law and internal data-export reviews, "no third-party IP call" is a materially cheaper compliance story than shipping IPs to an overseas API.
- Risk and fraud signals. Region mismatch between login location and the account's habitual province, or datacenter/IDC ISP names in the response, feed rules like "step-up auth on cross-region login" and "block registrations from hosting ranges." Cheap enough to run on every request rather than only sampled.
- Analytics and roadmap inputs. Province-level traffic segmentation lets you answer "is demand actually coming from 广东 or is it bot traffic?" and size regional feature bets (payment rails, logistics partners, CDN PoPs) without waiting on a data warehouse ticket.
- Routing and infra defaults. Coarse region signals for CDN/edge selection, timezone and locale defaults, and regional legal-notice rendering — decisions usually owned jointly with platform engineering.
- Internal tooling. Admin dashboards, support consoles, and audit logs benefit from showing an operator "where this account last logged in" without an external dependency or per-seat cost.
When to Consider This Package
Adopt when most of these hold:
- Your user base is predominantly in mainland China. This is the package's real strength; the underlying QQWry/纯真 dataset is maintained for Chinese IP allocations and ISP attribution.
- Province + city + ISP granularity is enough. If the decision is "which locale / which regional promo / is this suspicious," this fits. If you need latitude/longitude, DMA, or sub-city precision, it does not.
- You need offline or air-gapped lookups. Intranet apps, on-prem deployments, or environments where egress to a geo API is blocked or politically awkward.
- Marginal cost must be zero. High-volume, low-value-per-call lookups (every pageview, every log line) where a metered API is hard to justify.
- You are on Laravel/PHP with Composer. The integration cost is genuinely small — a service provider, a config file, one facade call.
- You accept owning the data pipeline. The binary must be refreshed on a schedule (QQWry is updated periodically; IP allocations drift). Budget for a cron/job, a versioned artifact store, and a smoke test that fails loudly when the file is stale.
Look elsewhere when:
- Your audience is global. QQWry coverage outside China is weak and unreliable; use MaxMind GeoIP2 or a commercial API for non-CN traffic, possibly behind the same internal interface.
- You need IPv6. QQWry-family databases are IPv4-centric. Verify before committing; many modern mobile carriers are IPv6-first.
- You need contractual reliability. 72 stars and effectively a single maintainer is a bus-factor of one. If IP resolution is on a critical path with an SLA, either wrap it behind your own interface with a hosted fallback, or buy.
- You need provenance and licensing certainty for the data. The MIT license covers the code, not necessarily the bundled database. Confirm you have the right to redistribute the
.dat inside your product or container image before shipping.
- Accuracy must survive mobile/CGNAT traffic. Carrier-grade NAT and mobile networks frequently resolve to a provincial capital or a carrier gateway, so city-level results for mobile users are directional, not precise. Don't build precise-geofencing logic on it.
- You need ASN, connection type, or proxy/VPN detection as first-class data. Use a dedicated vendor.
How to Pitch It (Stakeholders)
To executives: This is a small, MIT-licensed PHP library that answers "roughly where is this user?" using a locally stored Chinese IP database. Three things matter commercially. First, it is free at the margin — we can geo-personalize and geo-screen every request without a metered vendor bill, which changes the math on features we previously deprioritized for cost. Second, user IPs stay inside our own infrastructure, which makes the privacy and cross-border data review substantially simpler and faster. Third, the cost is not zero — someone must own refreshing the database file and monitoring its accuracy, and it depends on one volunteer maintainer, so we should treat it as an internal capability we own rather than a vendor we can escalate to. Recommended posture: adopt for China traffic behind our own thin abstraction layer, keep a hosted provider as a fallback for international users and for IPv6, and pin the dependency version.
To engineering: composer require gai871013/ip-location, publish config, call the facade — no API keys, no network calls, no rate limits, deterministic results, works in CI and air-gapped environments. Two real costs: (1) the shipped .dat becomes stale, so we need a scheduled refresh plus an alert when lookups start missing; and (2) the binary loads into process memory, so measure footprint under PHP-FPM before we put it on the hottest path — consider a cached lookup or a precomputed column if per-request cost shows up in profiles. Wrap it in our own GeoResolver interface with an IPv6/global fallback implementation behind it, so swapping providers later is a config change rather than a refactor. Pin the version, vendor the .dat, and read its redistribution terms before it goes into a container image.