Products
GG网络技术分享 2025-03-18 16:12 4
I need to show in a PHP
web page all the images in a folder. A pagination is required. The images can be more than 10,000, so a good performance is important, and here is where my doubt comes from, what is more efficient?
Paginate the images of the folder using scandir
.
Automatically save the name of all images in a database and load them with a Mysqli
query (probably also convenient to use a temporary cache).
Any other suggestions you can give me.
The website uses WordPress
as the engine, but the images are uploaded to a subdomain using a PHP file isolated from Wordpress ...
I thought about saving the name of all the images like a WordPress Custom-Post-Type
(using mysqli
basic queries) and paginate them like any other publication, but I think that, due to the amount, it would harm the overall performance of the website (because the custom-post-type
are saved in the same table as the other publications)...
The website receives more than 30 thousand daily visits that it must support.
PD: Sorry for the bad explanation but it is complicated to explain, and more in another language.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我需要在 PHP </ code>网页中显示文件夹中的所有图像。 需要分页。 图像可以超过10,000,所以良好的性能很重要,这是我怀疑的地方,更有效的是什么?</ p>
Paginate the 使用 scandir </ code>的文件夹图像。</ p> </ li>
自动保存数据库中所有图像的名称并使用 Mysqli <加载它们 / code> query(可能也方便使用临时缓存)。</ p> </ li>
您可以给我任何其他建议。</ p> </ li>
< / ul>
该网站使用 WordPress </ code>作为引擎,但使用与Wordpress隔离的PHP文件将图像上传到子域... </ p>
\\ n
我想保存所有图像的名称,如 WordPress Custom-Post-Type </ code>(使用
mysqli </ code>基本查询),并像任何其他出版物一样对它们进行分页, 但我认为,由于数量的原因,它会损害网站的整体性能(因为
custom-post-type </ code>与其他出版物保存在同一个表中)...... </ p>
该网站每天必须支持超过3万次访问。</ p>
PD:很抱歉这个说法不好,但解释起来很复杂, 更多用另一种语言。</ em> </ p>
</ div>
Use a custom table or a second database.
You are right to consider avoiding repeatedly calling scandir for every paginated request.
You can access the global$wpdb
object and do custom queries to manage the contents of your directory. I\'d lean towards just managing the image data separately from WordPress. Since you are already using a non WP upload script just create a new DB and use it to keep track of the directory contents in that script. Then paginated results is a very simple DB query. This keeps the WP database smaller and faster and is not overkill for the magnitude of images and visits you must handle.
Demand feedback