I have xml file with collection image urls and I want upload this url using php. I try using this function:
public function get_file($source, $destination)
{
$ctx = stream_context_create(array('http' => array('timeout' => 90)));
$content = file_get_contents($source, null, $ctx);
$f = fopen($destination, "wb");
fwrite($f, $content);
}
I try download about 7000 images, but after about 500 images, it ceases to copy images and hangs on the file. What's wrong?
Maybe your max_execution_time elapses? Try using set_time_limit
to check.
That's a horrific way to do it. With curl you could stream your download to disk instead of keeping the whole file in memory. I can imagine PHP simple messing up its memory and that's why it hangs. Use curl IMO. That aside, where are you downloading this from, do you get throttled by the other end?