Home  >  Article  >  Backend Development  >  What should I do if the data obtained by php curl is incomplete?

What should I do if the data obtained by php curl is incomplete?

藏色散人
藏色散人Original
2021-02-23 18:01:493854browse

Solution to incomplete data obtained by php curl: 1. Remove "CURLOPT_RETURNTRANSFER=true"; 2. Modify the nginx cache configuration of the data source server.

What should I do if the data obtained by php curl is incomplete?

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

php curl obtains incomplete data

When curl obtains data, the resulting string length is relatively large. For the same result, the data obtained each time is incomplete and the length is also different.

Try changing the HEADER information to except: but it still doesn’t work (the problem that can be solved is that the amount of data is too large and the result is empty).

Remove

 CURLOPT_RETURNTRANSFER = true

to print out the complete data

Solution:

Modify the nginx cache configuration of the data source server [Recommended :PHP video tutorial

fastcgi_buffers was modified from the original 8*128k to 8*1M

The following is quoted from https://segmentfault.com/a /1190000007513677

Nginx’s buffer mechanism, for the Response from FastCGI Server, Nginx buffers it into memory and then sends it to the client browser in turn. The size of the buffer is controlled by the two values ​​​​fastcgi_buffers and fastcgi_buffer_size.

For example, the following configuration:

fastcgi_buffers 8 4K;

fastcgi_buffer_size 4K;

fastcgi_buffers controls nginx to create up to 8 buffers of 4K size, and fastcgi_buffer_size is the size of the first buffer when processing Response, which is not included in the former. So the total maximum memory buffer size that can be created is 84K 4K = 36k. These buffers are dynamically generated based on the actual Response size and are not created all at once. For example, for an 8K page, Nginx will create a total of 2 buffers of 24K.

When Response is less than or equal to 36k, all data will of course be processed in memory. What if Response is larger than 36k? That's what fastcgi_temp does. The extra data will be temporarily written to the file and placed under this directory.

36Kb is buffered in memory, and the rest will be written to the file. The actual situation is that the user running Nginx Process does not have write permissions to the fastcgi_temp directory, so the remaining data is lost.

The above is the detailed content of What should I do if the data obtained by php curl is incomplete?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn