php - 服务器端使用json返回数据,请问大小的极限是多少?
迷茫
迷茫 2017-04-18 10:54:40
0
6
1234

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

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(6)
刘奇

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.

大家讲道理

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.

迷茫

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

大家讲道理

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.

洪涛

Not recommended, you can use paging and ajax to load

小葫芦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!