Solution to the problem that file_get_contents takes too long to run during the development of PHP WeChat public accounts

不言
Release: 2023-03-24 10:50:01
Original
2145 people have browsed it

The content of this article is about the solution to the long running time of file_get_contents during the development process of PHP WeChat public account. It has a certain reference value. Now I share it with you. Friends in need can refer to it

When I was developing the WeChat public account, I found that the code I wrote took too long to run. It took 16s to receive a message and verify it. After checking the code, I found that the execution time of such a statement exceeded the WeChat server response time , PHP file_get_contents() and file_put_contents(), The execution time of these two functions is relatively long, causing the WeChat server to send messages to the server three times, each time for 5 seconds No response was received, but checking the database it was found that the data has been saved, as shown in the figure below,

indicates that the subsequent code has been executed , but the previous verification time was too long, causing the server to return this message, and other subsequent methods, as shown in the figure below:

fopen($_SERVER['DOCUMENT_ROOT']."/usericon/" . $openid.".jpg" ,'a');
	fwrite($resource, $file);
	fclose($resource);
Copy after login

To replace the two functions file_get_contents() and file_put_contents() to save pictures, the execution time is much faster. It only takes 1 to 2 seconds to receive messages and store data!

Summary: fie_get_contents(), and file_put_contents(), the execution time is too long, causing the server to not respond to the WeChat server, just replace it~!

#              

The above is the detailed content of Solution to the problem that file_get_contents takes too long to run during the development of PHP WeChat public accounts. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template