简体   繁体   中英

PHP Downloadscript - Which HTTP-statuscode for maximum connections?

i have programmed a downloadscript in PHP, that allows User to download files from my server.

I have programmed, that only 2 connections per Download are available, that works.

My question is, which HTTP-statuscode can/must i send to inform the users downloadmanager that the maximum connections reached, when they already have 2 connections per download?

There is no "maximum connections" code, but either 429 or 503 is probably what you're looking for:

429 Too Many Requests

The 429 status code indicates that the user has sent too many requests in a given amount of time ("rate limiting").

The response representations SHOULD include details explaining the condition, and MAY include a Retry-After header indicating how long to wait before making a new request.

10.5.4 503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.

Note: The existence of the 503 status code does not imply that a server must use it when becoming overloaded. Some servers may wish to simply refuse the connection.

You can view all codes in the spec plus this list of additional codes .

I do not know of a way to tell that they reached the maximum. Only that they tried to download too many and err on the 3rd connection.

The one error I would probably use is 429, "Too Many Requests".

From RFC 6585:

http://tools.ietf.org/html/rfc6585#page-3

  1. 429 Too Many Requests

    The 429 status code indicates that the user has sent too many requests in a given amount of time ("rate limiting").

    The response representations SHOULD include details explaining the condition, and MAY include a Retry-After header indicating how long to wait before making a new request.

    For example:

    HTTP/1.1 429 Too Many Requests Content-Type: text/html Retry-After: 3600

    Too Many Requests

    Too Many Requests

    I only allow 50 requests per hour to this Web site per logged in user. Try again soon.

    Note that this specification does not define how the origin server identifies the user, nor how it counts requests. For example, an origin server that is limiting request rates can do so based upon counts of requests on a per-resource basis, across the entire server, or even among a set of servers. Likewise, it might identify the user by its authentication credentials, or a stateful cookie.

    Responses with the 429 status code MUST NOT be stored by a cache.

A good place to find many of the code actually in use by either a large number of servers or large companies is Wikipedia:

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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