Website I'm developing is showing products on sale and a lot of them are being updated and imported from XML (imported/updated 2x a day).
The problem is with getting product images. Some of them do not display even if url is provided.
Some XML contain from tens of items to hundreds of them.
The code loops through each item, gets all the data and then the image.
Example code regarding getting the image :
if (@file_get_contents($i->image)) {
$name = uniqid(rand(), true) . '.jpg';
$img = $name;
$url = $i->image;
$destinationPath = public_path() . '/img/upload/Items/'.$name;
@file_put_contents($destinationPath, @file_get_contents($url));
} else {
// do something else if there is no image
}
- Is my approach wrong here ?
- Remote server can't keep up with file requests ? And before each request need some pause ?
- If items are updated 2x daily I shouldn't bother with saving images locally and give img src the external url from XML ?
- Better use cURL() ?
- If approach is accepted what improvement in needs ?
Thank you.