简体   繁体   English

php 视频和照片上传:存储在数据库中 vs. 上传

[英]php video and photo uploading: storing in database vs. uploading

I am going to be approaching a large site in the near future that will require hundreds, maybe thousands of videos to be uploaded and stored.我将在不久的将来接近一个需要上传和存储数百甚至数千个视频的大型站点。 In addition, many images will need to be uploaded but not nearly as much, and they will be small in size.此外,需要上传许多图像,但不会那么多,而且它们的尺寸会很小。 Up until now, I've always used php and mysql as follows:到目前为止,我一直使用 php 和 mysql 如下:

  • upload an image上传图片
  • store the file name in the database将文件名存入数据库
  • reference a folder + filename in the database to display file引用数据库中的文件夹+文件名来显示文件

However, I've done some research on some BLOB storing images and files in the database and unsure of which way is best for this potentially large-scale project.但是,我对一些在数据库中存储图像和文件的 BLOB 进行了一些研究,但不确定哪种方式最适合这个潜在的大型项目。 Should I continue uploading the way I've been, or is it more efficient to use the BLOB type in mysql?是继续按照之前的方式上传,还是使用mysql中的BLOB类型效率更高? I'm afraid that by storing lots of videos and images in a database, it could get to be too much data or too slow, but I could be completely wrong.恐怕通过在数据库中存储大量视频和图像,它可能会变得太多数据或太慢,但我可能完全错了。 Please let me know any and all suggestions you have.请让我知道您的所有建议。

Storing images in BOLB is not efficient.BOLB中存储图像效率不高。 It will be difficult to manage.这将很难管理。 Your database will become large.你的数据库会变大。

It will be slower then serving a file from the server with a PHP script它会比使用 PHP 脚本从服务器提供文件要慢

Ok, so the two big areas are: backup, and change好的,所以两大领域是:备份和更改

Backup备份

Depending on the DB engine you choose, backups require locking / dumping / unlocking.根据您选择的数据库引擎,备份需要锁定/转储/解锁。 The bigger the database the longer the lock will be there.数据库越大,锁存在的时间就越长。 You could use some features (master/slave) to allow hotsyncing (backups without the locks) but there's a risk the backup won't completely cover the dataset, and the scale of the DB is still a factor.您可以使用一些功能(主/从)来允许热同步(没有锁的备份)但是存在备份不会完全覆盖数据集的风险,并且数据库的规模仍然是一个因素。 If large files are simply files (rather than DB BLOBS), it's just a matter of making a backup strategy for the file system, and since they're probably static this just means having multiple copies stored (this could even be by design at upload - store on server A and server B).如果大文件只是文件(而不是 DB BLOBS),这只是为文件系统制定备份策略的问题,因为它们可能是 static,这意味着存储多个副本(这甚至可以在上传时设计) - 存储在服务器 A 和服务器 B 上)。

Change改变

Do you expect your system to stay the same?您希望您的系统保持不变吗? It sounds like you will have scaling issues.听起来您会遇到缩放问题。 Might you move the DB to another server, the file storage to another server or SAN (or S3 etc) as your system grows?随着系统的增长,您是否可以将数据库移动到另一台服务器,将文件存储移动到另一台服务器或 SAN(或 S3 等)? If you've got it all locked in the DB you have to rely on DB only solutions to deal with the swelling size (large expensive servers, master/slaves etc).如果您将所有内容都锁定在数据库中,则必须依靠仅使用数据库的解决方案来处理不断膨胀的规模(大型昂贵的服务器、主/从等)。 Of course you could store the files in one DB (less backup requirements, doesn't mess around with your data DB) and other data in another... but a filesystem is a DB of sorts.当然,您可以将文件存储在一个数据库中(较少的备份要求,不会弄乱您的数据数据库),而将其他数据存储在另一个数据库中……但是文件系统是一种数据库。

So所以

So for backups and scaling storing large files as files and not BLOBs is a better solution.因此,对于备份和缩放,将大文件存储为文件而不是 BLOB 是更好的解决方案。 If the files were small (low MP JPGs for example) the balance may shift.如果文件很小(例如低 MP JPG),平衡可能会发生变化。 But for large files there's no point in the overhead of DB processing, and the extra load requirements it puts on the DB server.但是对于大文件来说,数据库处理的开销和它对数据库服务器的额外负载要求是没有意义的。 Keep 'em separate.让他们分开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM