When using file_get_contents inside while is a delay of 5-10 seconds, is there any solution? It is necessary to speed up the process somehow).

file_get_contents Reads:

 while (true) { $String = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=D809927A12701C14A968491B9518BBB6&steamids=76561198212513347"); $mail = explode(' ', $String); $mail = explode('"', $mail[8]); $mail = $mail[3]; if ($mail == '') { $mail = '../img/no-avatar.jpg'; } echo $mail; } 
  • What does file_get_contents read? It would be nice to see a little more code - Dmitriy Simushev
  • I think this problem is due to the speed of response - alias
  • one
    Firstly, to find the soap you need to use json_decode better, and secondly, why read static information in an infinite loop? - koks_rs
  • I didn’t write while ($prof = mysql_fetch_array($pro)) - Sauron

2 answers 2

The time file_get_contents spent on the http request.

Therefore, to speed it up, you need to connect a very fast Internet. A good communication channel should be from your server to the end node. Making someone else's server respond faster you can not)

  • Or it’s easy to use CURL at least a little faster) - Sauron
  • curl is not faster - the same) Just in curl, more options can be set, headers get, not just body. - jekaby 7:04 pm

It is possible that redirects occur during the call, so the wait is long. You can also try to replace with CURL or Soket. It works faster.

  • I compared the answers shown: from file_get_contents Time: 0.34765291214s. CURL Time: 0.271059989929s.But sometimes when you restart, CURL jumps out by 0.7 ... - Sauron
  • Try to look in what mode php is running, by chance not in without-curl? - And
  • @Sauron, well, so if you have a request execution time of 0.34765291214, what are we optimizing? - koks_rs
  • Here an example is shown over one request if output through while 10 times, it outputs within 5-10 seconds. That is, it takes a long time ... - Sauron