速度:MySQL与文件输出 [英] Speed: MySQL vs File Output

查看:147
本文介绍了速度:MySQL与文件输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,每次执行大约1个小时,在运行时,它需要存储一个稳定的注释,以便稍后查看。基本上,每条评论都包含一个时间戳和一个简短的描述,比如2/25/2010 6:40:29 PM:更新了255的价格。

那么哪个更快,将其输出到.txt文件,或者将其插入MySQL数据库?另外,我应该使用从PHP的日期()的时间戳,或者我应该在MySQL中创建一个时间对象?



我的问题的第二部分是,运行一个小时左右,我应该连接到MySQL,插入数据,并关闭连接到MySQL数据库,每次我记录一个评论,或者我应该只连接一次,为程序运行时插入数据,然后关闭程序退出时的连接,创建初始连接后大概一个小时?

预先感谢您的所有建议。

这取决于您在一天结束时对数据的需求。您是否需要对滚动浏览文件之外的数据进行审计?如果您不需要浏览数据或永久存储数据,那么平面文件将比MySQL更快,如果您只是追加到文件的末尾,则很可能是这样。



如果您需要更有用的数据,则需要将其存储在mysql中。我建议你像下面这样构建你的表:

  id int 
timestamp datetime now now()
desc varchar

这样你就不必在PHP中实际创建一个时间戳,只要让mysql工作,那么你将能够做你的表更复杂的查询。但是,您想要考虑的另一个考虑因素是进入该表的数据量,因为这也会影响您的最终决定。


I have a php script that will execute for about 1 hour each time, and during it's runtime, it will need to store a steady stream of comments about what it's doing for me to view later. Basically, each comment includes a timestamp, and a short description, such as "2/25/2010 6:40:29 PM: Updated the price of item 255".

So which is faster, outputting that to a .txt file, or inserting it into a MySQL database? Also, should I use the timestamp from PHP's date(), or should I create a time object in MySQL?

Second part of my question is that since the program is going to run for about an hour, should I connect to MySQL, insert data, and close the connection to the MySQL database each time I log a comment, or should I just connect once, insert data for the runtime of the program, and then close the connection when the program exits, about an hour after creating the initial connection?

Thank you in advance for all your advice.

解决方案

It depends on your need for the data at the end of the day. Do you need to be able to do Audits on the data outside of scrolling through a file. If you don't need to browse the data or store it in perpetuity, then a flat file will be faster than MySQL, most likely, if you are just appending to the end of a file.

If you need the data to be more useful, you'll want to store it in mysql. I would suggest that you structure your table like:

id  int
timestamp datetime default now()
desc varchar

That way you don't have to actually create a timestamp in PHP and just let mysql do the work, then you'll e able to do more complex queries off of your table. But, another consideration you'll want to think about is the volume of the data going into this table, as that will also affect your final decision.

这篇关于速度:MySQL与文件输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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