douhe4336 2014-01-04 21:29
浏览 96
已采纳

将数据库保留在内存中,即使客户端脚本已断开连接

I need to preprocess some statistics data before writing it to the main database. My php-cli script retrieves data every 10 minutes and should store it somewhere. Every hour all saved data are preprocessed again and then writted to the main db.

I thought that sqlite should be nice solution if I would keep it in memory. I have not very big amounts of data (I am able to keep it in my RAM).

Actually, I am new to sqlite (previously I was working only with mySQL). I found here that I can use :memory: instead of file name to work with memory only. But after client is disconnected database is destroyed, and if I will try to connect again to :memory: from my script - it will be different (new, empty) database.

Is it right? If it is, how can I work with same database using different php script calls, if sqlite is stored in memory?

P.S. perhaps it is a solution to put sqlite file to some "magic" directory? (I am using linux)

  • 写回答

2条回答 默认 最新

  • dongyuanguang3893 2014-01-04 21:50
    关注

    First, linux is pretty smart about using a filesystem cache. Thus, reading data from a disk is often surprisingly fast, and you should measure if the performance gain is worth it.

    If you want to go ahead, one method you might consider is using a ramdisk. Linux provides a way to create a filesystem in memory, and you can place your sqlite file in there.

    # mkdir -i /mnt/ram
    # mount -t ramfs -o size=20m ramfs /mnt/ram
    # touch mydb.sql
    # chown apache:apache mydb.sql
    

    ... or something similar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM