gpt4 book ai didi

mysql - Perl:将 $dbh 交给模块。安全性和性能?

转载 作者:行者123 更新时间:2023-11-29 05:33:06 25 4
gpt4 key购买 nike

所以我有一个cgi脚本,

#!/usr/bin/perl -T

use strict;
use warnings;
use DBI;
use WebEngine;


my $dbh = DBI->connect('DBI:mysql:database', $username, $password)
|| die "Could not connect to database: $DBI::errstr";

my $we = WebEngine->new($dbh)
or die("Failed to instantiate WebEngine object:\n$!\n");

$userID = $we->register("MyUsername", $dbh);

此脚本创建一个数据库处理程序,然后使用我制作的模块来处理网站的大部分后端以注册用户名并返回用户 ID 号。

关于这个我有三个问题。

  • 在此脚本中创建此 $dbh 是否会通过保持数据库连接打开来提高性能?

  • 我可以将 $dbh 放在我的模块中而不用担心效率低下吗?

  • 将 $dbh(和相关信息(我在代码中以纯文本形式保存我的通行证;这样不好吗?))保留在不通过我的模块直接交互的模块中是否有安全优势网站?

最佳答案

Does creating this $dbh in this script increase performance by keepinga database connection open?

Could I put the $dbh in my module and not fear being inefficient?

通常,您希望最小化数据库连接打开的时间长度。同时打开大量连接会影响性能。您保持连接打开的时间越长,当很多人同时使用您的网站时,您积累的连接就越多。

另一方面,多次断开连接和重新连接也会影响性能。

如果您预计站点的流量很大,最好的解决方案是实现连接池。这使许多事件连接保持打开和可用状态,但不会将它们绑定(bind)到特定用户。 Here is a discussion of MySQL connection pooling with Perl .如果您以这种方式实现它,那么您会希望在尽可能短的时间内打开一个连接。这将是高效的,因为它不是一个“真正的”引擎盖下的打开——只是一个已经打开的连接的分配。

Is there a security benefit to keeping the $dbh (and the associatedinfo(I keep my pass in plain text in the code; is that bad?)) in themodule that is not directly interacted with through my website?

如果该模块位于网络无法访问的文件夹中,那可能会有一点好处。但是,实际上,您不应该以明文形式存储密码。 Here is a discussion of some other options.

关于mysql - Perl:将 $dbh 交给模块。安全性和性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13043648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com