None of the two options will solve the problem of using server resources. Of the two, however, I would recommend option 1. The second method will delay the page loading, which will slow down the website speed and lower your SEO ratings.
The best option for you is something like:
foreach($items as $item) { echo '<img url="url_to_my_website/get_image.php?id='.$item->id.'" />' }
Then when the magic happens, get_image.php :
if(file_exists('/path_to_local_storage/image_'.$id.'.png')) { $url = '/path_to_images_webfolder/image_'.$id.'.png'; $img = file_get_contents($url); } else { $url = get_from_web_service($id); $img = file_get_contents($url); $imgname = end(explode('/', $url)); file_put_contents($imgname, $img); } header("Content-Type: image/png"); echo $img;
That you only run a request for a web service once per image, and then save it in your local space. The next time the image is requested, you submit it to your local space by skipping the request for a web service.
Of course, given that image identifiers are unique and persistent.
This is probably not the best solution, but should work well for you.
source share