In the photo gallery template (CMSMS) I use the following code:
<ul> {foreach from=$images item=image} {$imagesize=getimagesize($image->file)} <li> name : {$image->file} <em>width :</em> {$imagesize[0]}- <em>height:</em> {$imagesize[1]} </li> {/foreach} </ul>
Each time the gallery is loaded, the dimensions (width and height) of only some of the images are retrieved, sometimes all of them. It's completely random and not necessarily the same image. Obviously I tried different images from different sources.
I encountered the error Open Stream failed: Connection refused. Ctrl F5 gives randomly
This is a shared hosting (OVH).
I created a php file and an images directory (lots of them) in the root of the website.
<?php function walkDir($path = null) { if(empty($path)) { $d = new DirectoryIterator('./testqdima'); } else { $d = new DirectoryIterator($path); } foreach($d as $f) { if( $f->isFile() && preg_match("/(\.gif|\.png|\.jpe?g)$/", $f->getFilename()) ) { list($w, $h) = getimagesize($f->getPathname()); echo "<p>".$f->getFilename() . " Dimensions: " . $w . ' ' . $h . "</p>"; } elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') { walkDir($f->getPathname()); } } } walkDir(); ?>
It works fine and all images are processed.
So if anyone has encountered this problem before...
Many hosting providers impose connection limits and/or connection rate limits (or similar) to combat DDOS attacks (or for resource allocation considerations).
For connection rate limit, it is:
They may also employ other methods to limit the number of PHP calls/specific PHP method calls per second.
For template methods, each call to
getimagesize
is a separate request, and therefore may trigger throttling and result in a connection refused errorFor the PHP way, it is treated as a single request, so it will pass successfully.
I think you can only resolve the issue by talking to the hosting company (but they may not entertain you as they still need to resolve possible DDOS etc.), otherwise stick with the way your PHP parses image records (or switch Go to another hosting company/use a dedicated server)