PHP 错误跟踪器:存储附加文件
给定一个带有 SQL DB(MySQL、PostgreSQL、Oracle...)的 PHP bug 跟踪器项目,它应该能够存储每个 bug 的附加文件。
您基本上如何在数据库和数据库上存储信息(文件信息和文件本身)?磁盘?
例如
- 数据库:表bug将有一个相关的表bug_files,该表具有bug_id字段和一个filename字段,其中包含磁盘上文件的路径
- 磁盘:以有效的方式存储文件(避免单个目录中有太多文件),例如自动创建目录1-1000、1001-2000等所以我们可以有 /1001-2000/1234/bugfile.jpg 或随机子目录,例如 /z/e/x/q/1000_bugfile.jpg ?
...或者有更有效的方法吗?
谢谢。
编辑
这也取决于你想如何获得 对于这些文件,您是否使用后端 获取所有错误的网页和 为您创建链接?或者你 出现错误后收到电子邮件,并且 你必须手动找到它吗?我 我认为这个选择并不重要。
文件将通过错误跟踪 Web 应用程序列出/上传/下载(=> HTTP 上传/下载)。
除了开发人员/系统管理员之外,没有人能够查看自动生成的目录结构(但是拥有“清晰”的结构会更方便)。
Given a PHP bug tracker project with an SQL DB (MySQL, PostgreSQL, Oracle...), which should be able to store attached files for each bug.
How would you basically store info (file info and the file itself) on DB & disk?
e.g.
- DB: the table bug would have a related table bug_files having a bug_id field, and a filename field containing path to file on disk
- Disk: storing files in an efficient way (avoiding having too many files in a single directory), e.g. automatically create directories 1-1000, 1001-2000, etc. so we can have /1001-2000/1234/bugfile.jpg or random subdirectories like /z/e/x/q/1000_bugfile.jpg ?
...or are there a more efficient ways?
Thanks.
EDIT
It also depends on how you want to get
to these files, do you use a back-end
webpage that fetches all bugs and
creates the links for you? Or do you
get an e-mail after a bug occured and
do you have to find it manually? I
don't think this choice mathers a lot.
Files would be listed / uploaded / downloaded through the bug tracking web application (=> HTTP upload / download).
Nobody except developers / sysadmins would be able to view the automatically generated directory structure (however it would be more convenient to have a "clear" structure).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会让文件系统完成它的工作(文件存储)。数据库可用于文件存储,但它(通常)效率不高,例如文件数据可能会放入数据库缓冲区中 - 这本身并不坏,但它可能会占用其他表、行数据的资源并减少其他查询的性能。
基于日期和项目名称等有意义的组合创建目录将有助于减少同一目录中存在许多文件时的性能损失。
I'd let the file system do its job (file storage). Databases can be used for file storage but it's not (generally) as efficient, e.g. the file data may be put in the database buffers - this in itself isn't bad, but it may take resources away from other tables, row data and reduce the performance of other queries.
Creating directories based on a meaningful combination of date and project names etc. would help reduce the performance loss when having many files in the same directory.
我强烈建议使用可识别的目录结构,甚至可能是基于日期的目录结构或与错误文件名(部分)相匹配的目录结构。 Fe '20110506-bugfile' 将位于 /2011/05/06/ 中,也许这有点匹配,只有 2011/05/ 就足够了。
它还取决于您想要如何访问这些文件,您是否使用后端网页来获取所有错误并为您创建链接?或者在错误发生后您会收到一封电子邮件并且您必须手动查找它吗?我认为这个选择并不重要。
一个稍微不同的选项是将文件添加到表错误中的数据库中(http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading -files-to-mysql-database.aspx),那么您不必创建目录结构,但是,这当然不允许您使用 FTP 查找文件。
I'd strongly suggest using recognizeable directory structure, perhaps even date based or something that matches up with (parts) of your bug filename. F.e. '20110506-bugfile' would be in /2011/05/06/ Perhaps this is a little to matching and only 2011/05/ would be enough.
It also depends on how you want to get to these files, do you use a back-end webpage that fetches all bugs and creates the links for you? Or do you get an e-mail after a bug occured and do you have to find it manually? I don't think this choice mathers a lot..
A slightly different option is to add the file into your database in the table bug (http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx), then you don't have to create a directory structure, BUT, this would not allow you to find the files using an FTP ofcourse.