在主机中搜索或连接到数据库
在我的主机中,我有超过 1000 个文件夹,我预计它会达到超过 10000 个文件夹。
所有文件夹包含约 20 张图像。
我目前使用 scandir 列出一个文件夹中的所有图像,并仅向用户显示一张图像。
所以,这是我的问题:为了在所有这些图像中仅显示一张图像,我应该将它们的名称存储在数据库中,然后通过 id 加载它们,还是使用 scandir 并搜索整个文件夹?
顺便说一句,我的脚本类似于 mangafox.com。
In my host I have over 1000 folders and I expect it to reach over 10000 folders.
All folders contents about 20 images.
I am currently use scandir to list all images in one folder and show only one image to user.
So, here is my question: for showing only one image in all of those images, should I store their name in the database and then load them by there id's, or use scandir and search entire folder?
By the way, my script is something like mangafox.com.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法给出任何确切的数字,但数据库肯定会让您的网站更加敏捷。扫描目录以显示图像肯定不会像在数据库中快速查找图像路径并使用它那样缩放。
此外,您还可以使用该数据库来获取有关图像的其他元数据,例如评论或艺术家信息,仅使用文件系统很难将它们添加到图像中。
I can't really give any hard numbers, but the database will definitely make your site snappier. To scan directories for showing an image definitely won't scale as well as just quickly looking up a path to the image in the database and using that.
Also, you can use the database for other metadata regarding the images, for example comments or artist info that can be more difficult to add to an image using just the file system.
看起来如果这是一个频繁的活动 - 您不想一直运行
scandir
。但是,如果文件频繁更改,那么您就增加了保持数据库与文件系统同步的额外问题。这实际上是简单但有时很慢(使用
scandir
构建文件列表)和复杂但更快(必须同步数据库和文件系统)之间的权衡。我的建议首先是构建一个表示结果的数组或
scandir
并将其缓存到文件系统。这可能更容易保持同步,并且仍然提供更快的性能(假设它针对单个文件夹,而不是整个结构)。Seems like if this is a frequent activity - you don't want to run
scandir
all the time. However, if the files change frequently, then you've added an additional problem of keeping the database synced with the filesystem.It's really a trade off between simple, but sometimes slow (using
scandir
to build the file list) and complex, but faster (having to sync database and file system).My suggestion would first be to build an array representing the results or
scandir
and cache that to the file system. That may be easier to keep in sync, and still provide faster performance (assuming it's for a single folder, not the entire structure).