getimagefile() 随机工作

问题描述 投票:0回答:1

在照片库模板 (CMSMS) 中,我使用此代码:

<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>

每次加载图库时,只会检索一些图像的大小(宽度和高度),有时会检索所有图像。它是完全随机的,不一定是相同的图像。我显然尝试了不同来源的不同图像。

我有一个无法打开流的错误:连接被拒绝。 Ctrl+F5 随机给

这是一个共享主机(OVH)。

我在网站的根目录下创建了一个 php 文件和一个图像目录(很多)。

 <?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();

?>

它完美地工作,所有图像总是被处理。

所以如果有人以前遇到过这个问题......

php smarty
1个回答
0
投票

许多托管服务提供商会施加连接限制和/或连接速率限制(或类似方式)来应对 DDOS 攻击。

对于连接速率限制,它是:

Connection Rate Limit: a number that specifies the number of 
new connections accepted per second for the virtual server.  

对于模板方法,each

getimagesize
的调用是一个separate请求,因此可能会触发限制限制并导致连接被拒绝错误

对于PHP方式,它被视为一个单一的请求,因此它成功通过。

我认为你只能通过与托管公司交谈来解决问题(但他们可能不会招待你,因为他们仍然需要解决可能的 DDOS),

否则请

  1. 坚持您的 PHP 解析图像记录的方式或
  2. 只需将图像尺寸存储在您的数据库表中
© www.soinside.com 2019 - 2024. All rights reserved.