简体   繁体   English

如何使用PHP从Rackspace Cloud Files容器内的文件夹中获取文件夹大小?

[英]How to get folder size from folder inside Rackspace Cloud Files container using PHP?

Basically I have created a container inside Rackspace Cloud Files, lets say work . 基本上,我在Rackspace Cloud Files中创建了一个容器,可以说work Inside work I have so many folders by username (dynamic folders as new users register and allocate 1 GB of space). work我有很多按用户名命名的文件夹(随着新用户注册并分配1 GB空间,动态文件夹)。 Every time a user uploads a file, I want to check whether the user exceeds his limit or not before allowing him to upload. 每次用户上传文件时,我都想在允许他上传之前检查用户是否超出了限制。 I am using the Laravel PHP Framework along with Rackspace open cloud SDK. 我正在使用Laravel PHP框架以及Rackspace开放云SDK。

Questions: 问题:

  1. I want to get folder size of particular user's folder created under main container("xyz"). 我想获取在主容器(“ xyz”)下创建的特定用户文件夹的文件夹大小。

  2. Is there any other way to achieve whether user has exceed limit or not? 还有其他方法可以实现用户是否超出限制?

  1. I want to get folder size of particular user's folder created under main container("xyz"). 我想获取在主容器(“ xyz”)下创建的特定用户文件夹的文件夹大小。

When performing a container listing, you can provide a "prefix" and "format" query parameter to only return objects that begin with a specific prefix (in your case, the username), and return the results in the format JSON/XML. 在执行容器列表时,可以提供“前缀”和“格式”查询参数,以仅返回以特定前缀(在您的情况下为用户名)开头的对象,并以JSON / XML格式返回结果。 When results are returned in JSON or XML, they include additional information about the objects. 当以JSON或XML返回结果时,结果将包含有关对象的其他信息。 The following is an example JSON response: 以下是JSON响应示例:

[
    {
        "bytes": 13,
        "content_type": "text/plain",
        "hash": "8ddd8be4b179a529afa5f2ffae4b9858",
        "last_modified": "2015-01-27T00:08:44.671230",
        "name": "<username>/some_object.txt"
    },
    ...
]

NOTE: With this solution, if you get back 10k objects, you will want to look into using the “marker” query parameter to page your results. 注意:使用此解决方案,如果您获得了1万个对象,则需要使用“标记”查询参数来分页结果。

Additionally you might consider sharding your users into multiple containers. 另外,您可能会考虑将用户分片到多个容器中。 We recommend doing this to help with getting back more accurate results as far as the eventual consistency window (more on this later) is concerned. 我们建议您这样做,以帮助获得有关最终一致性窗口(稍后会详细介绍)的更准确的结果。 For example, create containers “work_0” through “work_9999” and determine which users go to which containers with something similar to the following: 例如,创建容器“ work_0”到“ work_9999”,并确定哪些用户转到哪个容器,其内容类似于以下内容:

$user_md5 = md5($username);
// Only use part of the md5sum, unless you have support for big (128-bit) integers
$user_int = hexdec(str_split($user_md5, 7)[0]);
$container_id =  $user_int % 10000;
$container_name = "work_$container_id";
print "Container for user \"$username\" is \"$container_name\"\n";
  1. Is there any other way to achieve whether user has exceed limit or not. 是否有其他方法可以实现用户是否超出限制。

If you have restrictions on how quickly your users will grow, or can limit the number of total users, then you might consider creating a container per user. 如果您对用户的增长速度有限制,或者可以限制用户总数,则可以考虑为每个用户创建一个容器。 The downside to this, is you will limit the number of users you can support by the maximum number of containers per account (500,000). 不利的一面是,您将通过每个帐户的最大容器数(500,000)来限制可以支持的用户数。 But it would allow you to use the container quota feature. 但这将允许您使用容器配额功能。 Using this feature, if you attempt to PUT an object and are over the quota, you will receive a HTTP 413 response. 使用此功能,如果您尝试放置对象且超出配额,则会收到HTTP 413响应。 You would also be able to check a user's usage with the "X-Container-Bytes-Used" header. 您还可以通过“ X-Container-Bytes-Used”标头检查用户的使用情况。

NOTE: I previously mentioned a “eventual consistency window”. 注意:我之前提到过“最终一致性窗口”。 In some cases, container listings/quotas might not update immediately, but they are eventually updated. 在某些情况下,容器列表/配额可能不会立即更新,但最终会更新。 In most situations this latency is either unnoticeable or minimal. 在大多数情况下,这种延迟不是很明显,就是很小。 However, if your use case requires that users absolutely are not allowed to upload beyond their quota, then you might have to look for an alternate method for tracking the user's usage (for example a local database). 但是,如果您的用例要求绝对不允许用户上传超出其配额的文件,那么您可能必须寻找一种替代方法来跟踪用户的使用情况(例如本地数据库)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM