duankanjian4642 2014-04-21 21:46
浏览 44
已采纳

如何限制用户存储空间php

I can't figure out the best way to limit a user's storage space on my php based app. I found another question but it doesn't seem to be an optimal way to handle this problem. The answers for that question suggest running a mysql SUM command to get the space a user is currently using. Is this efficient? What do other people usually do?

My case involves storing images for users. The images are loaded onto a cloud storage provider and I keep a record of the file size and name in my local database. Let's say that the maximum space a user gets is 10 GB. If each image is 300 kb after compression, that would be ~33,000 images per user. If there are 1,000 users, that would be ~33,000,000 images and thus ~33,000,000 rows in a table. This question suggests that the sum command is kinda slow when that many rows are considered.

Another option I thought of would be to increment and decrement a counter value every time an image is uploaded or deleted, but this might run into consistency and syncing problems. hm...

  • 写回答

1条回答 默认 最新

  • douzhajie7168 2014-04-21 21:52
    关注

    I think #increment and decrement a counter value# will be your solution, to keep consistency, you can run a cronjob to query a slave database and sync the value at certain period of time(or run the script when you maintenance your database). I am using this way now, so far works good.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名