- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前我正在将遗留代码库迁移到 PHP 7.1。代码库使用单个数据库对象作为 PHP 已删除的 mysql 函数的包装器。因此,简单的方法似乎是将所有这些 mysql 函数替换为新的 mysqli 函数。
没有问题...
然而,当我将重构后的代码注册到生产服务器时,mysql服务器负载飙升。所以就在那时我发现 mysql_connect
试图重用 mysql 连接(或类似的东西):
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.
mysqli_connect
没有这样的行为,所以我们确实看到大量的 mysql 连接被打开。
然后我们通过自己实现 mysqli 对象缓存来解决这个问题。因此,当一个请求尝试打开与同一用户/数据库组合的另一个连接时,我们会重新使用已建立的连接。
这确实有很大的不同,但是我们仍然看到更高的数据库负载(大约高 5 倍)。
我还缺少什么吗?有什么好主意吗?当然,这些问题可能仍然是我们的代码库所特有的,但我希望只是有一些我忽略的 mysqli 扩展。
旁注:我们现在不想使用持久连接,因为这可能会带来其他复杂性。
最佳答案
很可能每个脚本中仍然偶尔有一个或两个孤立连接。确保您的代码每个实例仅连接一次。
we fixed that by implementing mysqli object caching ourself.
在 PHP 中,对象缓存已经实现。您只需确保仅建立一次连接,并且在整个脚本执行过程中仅使用保持该连接的单个对象。
we do not want to use persistent connections just now, because that may give other complications.
正是如此。在一个脚本中拥有无数个连接,持久连接将立即杀死您的数据库。
关于PHP 的 mysql 迁移到 mysqli 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46670930/
这个问题已经有答案了: php, mysql - Too many connections to database error (6 个回答) 已关闭 8 年前。 伙计们,我的 opencart 网站
这是我想要的,但不能让它与新的 MySQLi 一起工作,只是因为我的主机没有所有新的 php 等... 但是一定有某种解决方案,或者这就是 MYSQLI 能做的? 请不要谈论 PDO,因为即使是丑陋的
这个问题在这里已经有了答案: Is there a way to see a prepared query as it will be executed on the database? [dupli
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
如何在扩展类中实现 mysqli? 我正在上传图像并将其存储在 MySQL 数据库中,但出现此错误: Notice: Undefined variable: mysqli in ...ecc/ecc/
我终于切换到 mysqli 了。 但是我发现了显着的性能差异。 我有一个脚本,可以进行大约 25.000 个查询。该脚本使用 mysqli 和 mysqlnd 作为驱动程序需要 15 秒10 秒使用
这个问题已经有答案了: Why can't I run two mysqli queries? The second one fails [duplicate] (2 个回答) 已关闭 4 年前。 我
这个问题已经有答案了: mysqli::query(): Couldn't fetch mysqli (4 个答案) 已关闭 6 年前。 这是我当前的代码: query("SELECT * FROM
这个问题在这里已经有了答案: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must
我正在尝试连接到我的数据库,但当我使用 127.0.0.1 而不是本地主机时出现错误。 Warning: mysqli::mysqli(): (HY000/2002): A connection at
使用 WHM 更新 mysql 后我的网站面临这个问题。 Warning: mysqli::mysqli(): Headers and client library minor version mis
我试图通过 MySQLi 将简单数据插入到我的 MySQL 表中,但是它拒绝插入,并且没有报告任何错误消息。 我想强调的是,当直接输入 PhpMyAdmin 时,此查询功能正常(当然,替换了变量) r
我正在使用用户断言函数,例如: debug_assert ( gettype($ob)=='object', "Not an object " .print_r($ob
我有一个每天只有大约 100 人访问的站点,但是当我以用户身份登录时收到此错误消息: Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1203):
我创建了一个 foreach 循环来将数据添加到 MySQL 数据库,但在将第一行添加到数据库后,我收到错误“mysqli::query(): Couldn't fetch mysqli”。 PHP
我正在使用 mysqli 实现一些基本的 getter 函数,并且正在考虑一种在错误检查中变得懒惰但仍然正确的方法。 所以我写了这种类型的代码段 if(!mysqli_stmt_bind_param(
我已经阅读了在线 php 手册,但我仍然不确定这两个函数的工作方式:mysqli::commit 和 mysqli::rollback。 我要做的第一件事是: $mysqli->autocommit(
这个问题在这里已经有了答案: What is the difference between single-quoted and double-quoted strings in PHP? (7 个答
我是一名优秀的程序员,十分优秀!