Reputation: 11198
I have a page that loads images dynamically via a file called thumb.php
This file takes the large image file, makes a thumbnail and outputs a jpg like so:
<img src="thumb.php?width=100&height=100&cropratio=1:1&image=/photos/45_Jumps-059.jpg" />
I have a problem on my server where when I reach around 60 requests (requests thumb.php 60+ times for all the images), the response I get back from the server is:
Remote server closed the connection before sending response header
and the image fails to load.
Is this like apache or php running out of memory or something? It stalls my whole server for about a minute before it starts working again.
Upvotes: 3
Views: 673
Reputation: 15364
The issue is most likely the maximum connection limit in Apache. It's set so the server can continue to function when it's being hit with too many simultaneous connections. It's easily configurable, but you mention you are on a shared host so it's unlikely you'll be able to change this.
In your scenario I would spread out the image requests by loading a few on page load, then use JavaScript to watch when the load is complete and add more images. Example with JQuery (untested):
<img src="" data-src="thumb.php?width=100&height=100&cropratio=1:1&image=/photos/45_Jumps-059.jpg" />
<img src="" data-src="thumb.php?width=100&height=100&cropratio=1:1&image=/photos/46_Jumps-059.jpg" />
<img src="" data-src="thumb.php?width=100&height=100&cropratio=1:1&image=/photos/47_Jumps-059.jpg" />
<script>
$("img[src='']").load(function() {
var next = $("img[src='']:first");
next.attr('src', next.data('src');
});
var first = $("img[src='']:first");
first.attr('src', first.data('src');
</script>
Upvotes: 1