在php中读取和写入dat文件
最近我使用 Maxmind geoip 来定位国家和地区基于ip的城市。 dat 文件中包含大量内容。但这些记录的检索会在一秒钟内完成。所以我很好奇学习和使用php中的技术。
首先,我看到一些视频文件正在使用此 .dat 扩展名文件,现在是文本信息。那么 .dat 扩展名实际上是什么?是否可以在 php.ini 中读取和写入?
谢谢!
recently i've used Maxmind geoip to locate country & city based on the ip. It has huge content inside the dat files. but retrieving of those records happens within a seconds. so i'm so curious to learn and use the technology in php.
First i've seen some video files are using this .dat extension files and now text information. so what is .dat extension actually? is it possible to read and write in php.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,dat 扩展名意味着一个通用文件,您可以在其中以您喜欢的格式编写您需要的内容。
我的意思是,在每个文件中您都可以这样做,但通常如果您找到 xml 文件,您会认为在其中找到了 xml 格式的文本;相反,如果您不知道文件是谁以及如何编写的,则 dat 文件不会被识别为可以使用特定软件解码的文件。
For what I know, dat extension means a generic file in which you could write what you need, in the format you please.
I mean, in every file you could do that, but generally if you find an xml file you assume that inside you find xml formatted text; on the contrary dat files are not recognized as something you can decode with a specific software if you don't know who and how wrote it.
这些文件很可能采用他们开发的自定义格式;如果它是开源的,您可以用 PHP 重新实现它(如果它还没有用 PHP 编写),或者可以通过 API 访问数据。
速度将来自于它将以某种方式建立索引,或者就像“对于每条记录,将 100 个字节进一步移动到文件中”。
The files will most likely be in a custom format that they developed; if it's open source you could reimplement it in PHP (if it isn't already written in PHP), or maybe access the data through an API.
The speed will come from the fact that it'll be indexed in some way, or it's like "for every record move 100 bytes further into the file".
这里有很多问题。
首先,该文件是一个数据库 - 它存储数据。有很多数据库模型——关系型、分层型、面向对象型、矢量型、超立方体型、密钥库型……所有这些模型都有现成的实现。
有些数据库比其他数据库更适合管理特定的数据结构。地理空间数据是一种常见的专业化 - 如此之多以至于许多其他数据库类型将提供矢量功能(例如 mysql 和 postgresql,它们是关系数据库)。
对于大多数数据库系统,使用数据库服务的应用程序不会直接访问数据文件 - 而是通过另一个进程来介导访问 - 这对于 PHP 特别相关,因为它通常作为多个独立进程运行,没有复杂的文件锁定功能。
因此,如果您希望自己实现 IP 到地理信息,我建议您坚持使用关系数据库或 nosql 密钥库(您不需要用于正向查找的地理空间内容)。
但请记住,IP 到地理查找数据并不像销售产品的人让您相信的那么准确/精确。如果您的目标是获取有关用户的准确位置信息,则 HTML5 geolocation API 提供更好的数据 - 问题是用户浏览器上的功能的可用性。
There's a lot of questions here.
First, the file is a database - it stores data. There are lots of database models - relational, herarchical, object-oriented, vector, hypercube, keystore....there are implementations of all these available off the shelf.
Some databases are more apposite to managing particular data structures than others. Geospatial data is a common specialization - so much so that a lot of other database types will provide vector functionality (e.g. mysql and postgresql which are relational databases).
For most database systems, the application using the services of the database does not access the data file directly - instead access is mediated via another process - this is particularly relevant for PHP since it typically runs as multiple independent processes with no sophisticated file locking functionality.
So if you were looking to implement IP to geography info yourself, I'd recommend sticking to a relational database or a nosql keystore (you don't need the geospatial stuff for forward lookups).
But do bear in mind that IP to geo lookup data is not nearly as accurate/precise as the peolpe selling the products would have you believe. If your objective is to get accurate position information about your users, the HTML5 geolocation API provides much better data - the problem is availability of the functionality on user's browsers.