search

Home  >  Q&A  >  body text

php - 服务器端使用json返回数据,请问大小的极限是多少?

我们想在后端查了服务器之后,返回数据量未知的json对象(每一条就是一个笔记数据)给前端。有可能上万条。

请问这样靠一个请求返回可以吗?有没有字符长度限制?
多谢

迷茫迷茫2802 days ago1319

reply all(6)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:56:40

    There must be some. When it comes to PHP specifically, php.ini has a limit of most post. By default, the maximum data transmission is 8M. If it is converted into characters, it may not be calculated. After all, there are methods for calculating characters in Chinese and English. The difference is that even if the transmission limit is continuously expanded, the number of characters transmitted will still be exceeded, so please transmit tens of thousands of data in segments. Even if the maximum limit is not exceeded, the more data is transmitted, the slower the corresponding speed will be.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:56:40

    There is no clear limit on the size of HTTP response.

    1. Generally, the server returns data to the client. If the server knows the size of the returned content, it can be specified through the Content-Length header.

    2. If the server itself does not know the specific size of data returned to the client (such as streaming data), it can use Chunked Transfer-Encoding to identify it.

    However, it is not a good idea for the server to return large segments of JSON, as it will cause the client to take too long to parse, and the user experience is not good. The best way is to paginate/segment the data, asynchronously, and request while parsing.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:56:40

    A request returns a large amount of json data, and the front-end parsing time is also very long. If asynchronous processing is not performed, the thread may be stuck. It is best to request in segments

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:56:40

    Yes, but you must consider the capabilities of both ends, especially the performance of the server, and the stability of the transmission. Generally speaking this is not recommended.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:56:40

    Not recommended, you can use paging and ajax to load

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:56:40

    I object to the previous ones who confused requests and responses.
    There is no size limit for downloads. It seems that when you download a file through http request, it will not say that the file cannot be downloaded if it is larger than the size.
    Returning json is actually responding to a byte file.
    So, unless the php execution times out during your return process, there is no return size problem.

    reply
    0
  • Cancelreply