I have an XML file localy. It contains data from marketplace.
It roughly looks like this:

```
<offer id="2113">
    <picture>https://anotherserver.com/image1.jpg</picture>
    <picture>https://anotherserver.com/image2.jpg</picture>
</offer>
<offer id="2117">
    <picture>https://anotherserver.com/image3.jpg</picture>
    <picture>https://anotherserver.com/image4.jpg</picture>
</offer>
...

```

What I want is to save those images in `<picture>` node localy.

There are about *9,000 offers* and about *14,000 images.*

When I iterate through them I see that images are being copied from that another server but at some point it gives `504 Gateway Timeout`.

Thing is that sometimes error is given after 2,000 images sometimes way more or less.

I tried getting only one image 12,000 times from that server (i.e. only `https://anotherserver.com/image3.jpg`) but it still gave the same error.

As I've read, than another server is blocking my requests after some quantity. 

I tried using `PHP sleep(20)` after every 100th image but it still gave me the same error (`sleep(180) - same`). When I tried local image but with full path it didn't gave any errors. Tried second server (non local) the same thing occured.

I use `PHP copy()` function to move image from that server. 
I've just used `file_get_contents()` for testing purposes but got the same error. 

I have 

```
set_time_limit(300000);
ini_set('default_socket_timeout', 300000);

```

as well but no luck.

Is there any way to do this without chunking requests?

Does this error occur on some one image? Would be great to catch this error or just keep track of the response delay to send another request after some time if this can be done?

Is there any constant time in seconds that I have to wait in order to get those requests rollin'?

And pls give me non-curl answers if possible.

> 
> **UPDATE**
> 
> 
> 

Curl and exec(wget) didn't work as well. They both gone to same error.

Can remote server be tweaked so it doesn't block me? (If it does).

p.s. if I do: `echo "<img src = 'https://anotherserver.com/image1.jpg'" />` in loop for all 12,000 images, they show up just fine.