RE: ip-to-country - summary
| From: | Divyank Turakhia | Date: | Fri, 25 Apr 2003 21:03:30 +0000 |
| Subject: | RE: ip-to-country - summary | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-17081@lists.php.net to get a copy of this message | ||
As of now, I cant think of any better method myself. As discussed
earlier, we need a method which can be implemented across all mirrors.
So we are only allowed to use functions that would be available across
all versions. We cannot use anything that would require recompilation of
php.
The method suggested by goba sounds like it would be fast enough and not
complex to code. Unless someone has an idea which would be drammatically
faster, we can and should go ahead with this.
We can auto generate the $where_to_start_for_ip_search array from the
db, each time we download an updated version. My guess is that goba has
already thought of tht.
Its 2:30am here, I will start work towards building the db tommo and I
should hopefully be able to post the link to download the new db on the
list soon.
- Div
> Well, I was unable to come up with anything better, then my
> indexable text
> file idea. What we need with this format:
>
> - three fields: iprange from and to and three letter countrycode
> - have all fields padded to a fixed length (actually only
> the first two
> are related, and they should be padded with zeros added to the
> left to let PHP recognized them as numbers, if they need to act in
> a comparision)
> - no char to separate the fields. This is not needed because of the
> fixed width nature of the data
> - \n (one byte) linending
>
> This way, one record will be (2*ipnumber_length+3+1) bytes.
> So we can build up
> an index for the IP numbers. This would mean that we need to
> define a step,
> with which we index the IP list. So something like:
>
> $where_to_start_for_ip_search = array(
> 0 => 0,
> 10000 => 15,
> 20000 => 23,
> [...]
> );
>
> This is a mapping between where (at what record) to start to
> search for an IP
> above that number. Then we can fseek() to that position, as
> we know the fixed
> size of records. From there we can start a normal linear
> search, that would
> probably be sufficient.
>
> Then when we find the right range and country, we set it in a
> cookie for the
> user, so it stays there, and we won't need to find out the
> country again.
>
> Divyank, I would like to ask you to create an output format
> like this, so we
> can start to write the script on our end to receive the file,
> process it to
> create the index, and deploy it to the mirror sites. Except
> if anyone has any
> objections to the above method, or can suggest a better one
> ;) Don't be
> afraid of suggesting anything revolutionary ;)
>
> Goba
>