通过 CMS 管理网站配置
我在 Stack Overflow 上读过与此问题非常相似的问题,但并不完全相同。
假设我的网站的每个页面上都包含以下 config.inc.php 文件:
<?php
$site_name = 'Acme Inc.';
$authenticate_with_ldap = true;
$ldap_host = 'ldap.example.com';
$ldap_port = 389;
$ldap_rdn = 'ldap-user';
$ldap_password = 'ldap-pass';
$ldap_dn = 'ou=example,dc=example,dc=com';
$smtp_username = 'smtp-user';
$smtp_password = 'smtp-pass';
$recaptcha_publickey = 'my-recaptcha-publickey';
$recaptcha_privatekey = 'my-recaptcha-privatekey';
?>
注意:我选择将网站配置保存在文件中而不是数据库中,因为该信息在整个网站上使用,并且它会需要更多的代码,而且我猜,必须始终在数据库中查询相同的信息会产生更多的开销。
现在假设网站管理员是那种更喜欢使用 CMS 编辑上述信息而不是手动编辑文件的人。我担心的是,当网站管理员单击“更新”按钮并且 PHP 脚本到达覆盖 config.inc.php 文件的 file_put_contents 函数时,可能会出现问题并损坏文件或由于语法错误或其他原因使其无法使用。
这是一个合理的担忧吗?我应该告诉网站管理员他应该坚持下去并手动编辑文件吗?我应该将信息存储在数据库中吗?或者我应该将信息存储在两个地方,以便如果文件弄乱,可以使用数据库中的信息重新生成它?
I've read questions on Stack Overflow very similar to this question, but not quite the same.
Let's say that I had the following config.inc.php file included on every page of my website:
<?php
$site_name = 'Acme Inc.';
$authenticate_with_ldap = true;
$ldap_host = 'ldap.example.com';
$ldap_port = 389;
$ldap_rdn = 'ldap-user';
$ldap_password = 'ldap-pass';
$ldap_dn = 'ou=example,dc=example,dc=com';
$smtp_username = 'smtp-user';
$smtp_password = 'smtp-pass';
$recaptcha_publickey = 'my-recaptcha-publickey';
$recaptcha_privatekey = 'my-recaptcha-privatekey';
?>
Note: I have chosen to keep the website configuration in a file instead of the database because the information is used all over the website and it would be a lot more code and, I'm guessing, a lot more overhead to have to query the database for the same information all the time.
Now let's say that the website administrator is the type of person who would prefer to edit the above information using a CMS as opposed to going in and editing the file manually. My fear is that when the website administrator clicks the "Update" button and the PHP script gets to the file_put_contents
function that overwrites the config.inc.php file, something could go wrong and either corrupt the file or make it unusable due to a syntax error or something.
Is this a reasonable concern? Should I tell the website administrator that he should just tough it out and edit the file manually? Should I store the information in the database instead? Or should I store the information in both places so that if the file gets messed up, it can be regenerated using the information in the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将该信息作为单行数据存储在数据库中,它不会被缓存吗?
If you store that info in the DB as a single row of data, wouldn't it be cached anyway?