中止读取文件时的 PHP 页面超时 [英] PHP Page timeout when aborting readfile

查看:44
本文介绍了中止读取文件时的 PHP 页面超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 php 视图,如下所示:

I have an simple php view which looks like this:

header('Content-Type: image/png');
readfile($this->image);
exit();

在这个例子中 $this->image 是例如 /data/pictures/thumbs/x/xyz.png.

In this example $this->image is for example /data/pictures/thumbs/x/xyz.png.

在 HTML 索引上,我加载了大约 20 个产品并使用上面的代码显示它们的产品图片:

On an Index HTML I load about 20 products and display their product image with the code above:

<img src="views/showimage.php?id=100"/>

当我现在加载包含产品的索引页面时,加载产品的每个缩略图需要很短的时间.如果我等到加载完成,我可以点击页面上的其他按钮并加载点击的内容.如果我不等到页面/图像被加载,我可以点击彼此的按钮,浏览器将超时.在此之后,我必须清理我的饼干,然后再做一次.

When I now load the index page with the products, it tooks a short time to load every thumbnail image of the product. If I wait until loading is completed, I can click on each other button on the page and it loads the clicked content. If I dont wait until the page /images are beeing loaded, I can click on each other button and the browser will run into a timeout. After this I have to clean my cookies and can do it again.

我发现,即使我没有让他完成加载,也可以加载页面 2 次.在第三次加载时,在页面加载完成之前点击导航,它遇到了超时......

I figured out, that its possible to load the page for 2 times, even though I dont let him complete loading. On the third load, and clicking on navigation before page loads completed, it rans into timeout...

这不是浏览器问题!

谁有什么想法?PHP 日志为空.

Whos having any idea? PHP Log is empty.

推荐答案

经过讨论,我们找到了解决方案.

After discussion we've found the solution.

问题的根源在于图像中的数据过多.每张图片的尺寸约为 40x27 像素,大小超过 1 Mb.

Root of problem was in excessive data in images. Each image had dimensions of around 40x27 pixels and size more than 1 Mb.

stripImage() 添加到使缩略图剥离过多数据(似乎是颜色配置文件)并将文件大小减小到几 kb 的部分.

Adding stripImage() into part that makes thumbnails stripped away excessive data (which seems to be color profile) and decreased file size to several kb.

这篇关于中止读取文件时的 PHP 页面超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆