- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有一个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/
因为我需要一个指向不同类中的 SDL_Window 的指针,所以我认为使用 shared_ptr 是个好主意。 //happens in class A::foo() //shared_Window_
我有一些通过 cron 定期运行的长期运行的 CLI PHP 脚本。我希望它们尽快完成,但又不会严重影响其他进程(例如 Web 服务器响应能力)。 目前我正在运行脚本 nice -n 19 并且还尝试
我想将 view.py 中的字符串数组移交给模板,并将该字符串用于 D3。 views.py: def index(request): template = loader.get_templa
我必须使用一个库函数,它为生成的字符串分配一点内存并返回一个 char*,期望调用者最终使用 free() 释放内存。 // Example declaration of the library fu
我想使用接受 UTF16-LE 字符串作为 (const char16_t* str, size_t length) 参数的库函数。 length 参数只需要为非空终止的字符串提供。该函数将复制字符串
我是一名优秀的程序员,十分优秀!