1
for ($x = 1 ; $x <= 100 ; $x++) {

        $file = "http://urlishere?parameter1={$x}"

        //An example JSON string.
        $jsonString = file_get_contents($file);

        // Additional processing here
}

Executing the above has occasionally thrown a warning with: Warning: file_get_contents(...): failed to open stream: HTTP request failed! HTTP/1.1 429 Too Many Requests

Can I use sleep() to create an interval between each call of file_get_contents? If no, what else can I do to solve the problem?

Also, how do I dump the details on how long to wait before the next request as per: https://httpstatuses.com/429

Can I use file_get_contents?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
forgodsakehold
  • 870
  • 10
  • 26
  • 1
    you can use sleep() . check how much time it will take to run only one time and then use that much time into sleep – Alive to die - Anant May 08 '17 at 07:53
  • You can do this way, as you ask, but try to think outside the box, why instead of getting all of those request, you simplify them in one call getting a single zip file, for example? – Diego N. May 08 '17 at 15:50

0 Answers0