简体   繁体   English

在php中使用纯文本数据库

[英]Using a plain text database in php

I am working on a small web application for a friend and am thinking about using a plain text file instead of MySQL, it just seems like a bit too much for the simplicity of this application. 我正在为一个朋友开发一个小型Web应用程序,并且正在考虑使用纯文本文件而不是MySQL,对于此应用程序的简单性来说似乎有点过多。

The application will basically let people put their name on a list from a web form. 该应用程序基本上可以使人们将其姓名放在Web表单的列表中。 There will likely be about 30-100 people putting their names on the list at a time, maybe sometimes upward of 200-300. 一次大约有30-100个人将其姓名列入名单,有时可能超过200-300。 Once all the names are entered the submission form will be closed and a single user will view the list and probably erase it soon afterwards. 输入所有名称后,提交表格将关闭,只有一个用户可以查看该列表,并可能很快将其删除。

What I am curious about is if there could be any issues with a lot of people trying to put their names on the list at the same time. 我很好奇的是,很多人试图同时将自己的名字列入名单是否会出现问题。 If somebody submits a name while the server is in the middle of writing to the file, will this cause the second person's submission to fail since the file is in use already, or will the server wait for one submission to be finished before starting another? 如果在服务器写入文件的过程中有人提交了名称,这是否会导致第二人的提交失败,因为该文件已被使用,还是服务器会在开始提交另一个文件之前等待一个提交完成?

No, it will not wait, google for "race condition". 不,它不会等待,谷歌搜索“比赛条件”。 If there is not much traffic on the submission form, that will not hurt, but I would recommend to use a mysql anyway, because the effort is quite the same. 如果提交表单上的流量不多,那不会有任何伤害,但是无论如何,我还是建议使用mysql,因为工作量是相同的。

I would use a simple text file and put the names line by line. 我将使用一个简单的文本文件,并逐行放置名称。 Every time you enter a new name, simple get the names/lines via 每次输入新名称,只需通过以下方式获取名称/行

$array_of_names = file("textfile.txt");

check if the new one already exists and if not add a new line. 检查新的行是否已经存在,如果不存在,请添加新行。 an exact example of that is given on http://php.net/manual/en/function.file.php 确切的示例在http://php.net/manual/en/function.file.php上给出

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

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