arrow_back How to Optimize php?

1 vote
How can I optimize the php code, which pulls the protocols through the get file, so that when the page refreshes are not pulled protocols, and they somehow cached or what can you think of?


$get_content = file_get_contents
Who didn't stretch out?
Are you reading a local file or over the network? )
nelson : $get_content = file_get_contents
What is a get file, and what protocols are we talking about?

1 Answer

1 vote
If we are talking about file_get_contents() with reading data from URL and not from local file, then the simplest option is to save read data to a local file. Local files are a great option for caching.
If you want to keep track of the data lifetime, you can use filemtime(), the timestamp of file modification.
It is highly desirable to use a flock on this file, so that several threads do not write to it simultaneously.