R
R
Rxd2014-10-05 13:50:57
PHP
Rxd, 2014-10-05 13:50:57

Why is File_get_contents too slow?

I use file_get_contens to work with STEAM, but almost immediately I ran into a very interesting problem:

$_MYKEY = "93291431A019B3FD12444E8377901C45";
   $_MYID  = "76561198018795706";
      
       $Time = time();
       $Response = file_get_contents("http://steamcommunity.com/profiles/".$_MYID."/inventory/json/570/2");
       $Time2 = time();
       echo '1  ='.($iTime2 - $iTime)."<br></br>";

       $iTime = time();
       $Response2 = file_get_contents("http://api.steampowered.com/IEconItems_570/GetPlayerItems/v0001/?key=".$_MYKEY."&format=json&language=ru&steamid=".$_MYID);
       $iTime2 = time();
       echo '2  ='.($iTime2 - $iTime)."<br></br>";

In the first case, file_get_contens receives a page of 1.5mb, the running time is 1-3 seconds.
In the second case, the page weighs only 300kb, but it loads many times longer, from 5 seconds or more, while it opens almost instantly in the browser. How can I fix this and is there an alternative, more productive way to get the information I need?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-10-05
@Rxd

curl and multi_curl.
You can through wireshark, etc. to monitor what is stupid where.

N
Nazar Mokrinsky, 2014-10-05
@nazarpc

Try to send the header (most likely you can add it via context):
Browsers are normally friendly with this, and file_get_contents() hangs until the timeout until it falls off.
You can try curl, send a request through a socket.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question