doupang9080 2012-12-24 13:45
浏览 39
已采纳

PHP session_sava_path()到MySQL表

I've been looking into making my own session handler for my PHP application, simply because I want to store the session data in a MySQL Memory table instead of on the local filesystem.

There are 4 main reasons for me to do this.

  1. The MySQL server is local, so reading from memory will be faster.
  2. Being able to list active users
  3. Making an easy way for an admin to read and modify a user session, without having them logging ind and out.
  4. Being able to run scripts after a session timeout, or a user "idle" variable in the session.

I can't seem to find any easy way for doing this.

I could use memcached, but it would result in doubling the session data in the memory on my server.

Does anybody know of an easy way, to force PHP at run-time, to use a MySQLi resource as session storage?

  • 写回答

1条回答 默认 最新

  • doushi6932 2012-12-24 13:52
    关注

    Actually Mysql offers a memcache interface that first uses memory and can later on persitent into a real database table.

    It can be simply configured via php.ini after you've create the tabels in your database server (see here):

    ; when using the "memcache" extension:
    session.save_handler=memcache
    ; when using the "memcached" extension:
    ; session.save_handler=memcached
    
    session.save_path="tcp://localhost:11211"
    

    You find it outlined here with PHP examples:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题