有没有一种方法可以在内存中维护200MB不变的数据结构并从脚本中访问它? [英] Is there a way to maintain a 200MB immutable data structure in memory and access it from a script?

查看:60
本文介绍了有没有一种方法可以在内存中维护200MB不变的数据结构并从脚本中访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个900万个IP的列表,并且通过一组哈希表,我可以创建一个恒定时间函数,如果该列表中有特定IP,则该函数将返回.我可以用PHP做到吗?如果可以,怎么办?

I have a list of 9 million IPs and, with a set of hash tables, I can make a constant-time function that returns if a particular IP is in that list. Can I do it in PHP? If so, how?

推荐答案

这个问题的有趣之处在于您可以前往的路线数量.

The interesting thing about this question is the number of directions you can go.

我不确定缓存是否是最好的选择,仅仅是因为数据量大且查询量相对较少.这里有一些想法.

I'm not sure if caching is your best option simply because of the large set of data and the relatively low number of queries on it. Here are a few ideas.

1)构建ram磁盘.链接您的mysql数据库表以使用ramdisk分区.我从来没有尝试过,但是尝试会很有趣.

1) Build a ram disk. Link your mysql database table to use the ramdisk partition. I've never tried this, but it would be fun to try.

2)Linux通常具有非常快速的文件系统.构建一个结构化的文件系统,将记录分解为文件,然后调用file_get_contents()或file_exists().当然,此解决方案需要您构建和维护文件系统,这也很有趣. rsync可能有助于使实时文件系统保持最新状态.

2) Linux generally has a very fast file system. Build a structured file system that breaks up the records into files, and just call file_get_contents() or file_exists(). Of course this solution would require you to build and maintain the file system, which would also be fun. rsync might be helpful to keep your live filesystem up to date.

示例:

/002/209/001/299.txt

<?
$file = $this->build_file_from_ip($_GET['ip']);
if(file_exists($file)) {
    // Execute your code.
}
?>

这篇关于有没有一种方法可以在内存中维护200MB不变的数据结构并从脚本中访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆