我确定我的代码出现了问题..已经环顾四周但却找不到任何线索...希望有人能够在这里堆叠.. 我的网站基本上是在Opencart框架下设计的,现在它仅供用户访问我的网站查看文章。 每个用户从Facebook或其他社交媒体进入我的网站将导致只执行2个数据库查询的页面。并且这两个查询都不是连接(我研究在加入表时某种程度上减慢了)其他表。 好吧让我们直截了当。 几天前,我的网站突然出现故障,我在谷歌分析中检查了当时5分钟左右的1000名活跃用户。然后我登录到服务器并检查进程列表,我发现列表中有数百个睡眠过程。
| Id | User | Host | db | Command | Time | State | Info |
| 28573 | goodycom_user | localhost | goodycom_db | Sleep | 9 | | |
| 28577 | goodycom_user | localhost | goodycom_db | Sleep | 9 | | |
| 28627 | goodycom_user | localhost | goodycom_db | Sleep | 8 | | |
| 28778 | goodycom_user | localhost | goodycom_db | Sleep | 6 | | |
| 28919 | goodycom_user | localhost | goodycom_db | Sleep | 5 | | |
| 28931 | goodycom_user | localhost | goodycom_db | Sleep | 4 | | |
| 29026 | goodycom_user | localhost | goodycom_db | Sleep | 3 | | |
| 29088 | goodycom_user | localhost | goodycom_db | Sleep | 3 | | |
| 29106 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29108 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29113 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29132 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29152 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29177 | goodycom_user | localhost | goodycom_db | Sleep | 2 | | |
| 29272 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29299 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29308 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29310 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29311 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29313 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29314 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29315 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29317 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29318 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29319 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29320 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29321 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29322 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29323 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29324 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29325 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29326 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29327 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29328 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29329 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29330 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29331 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29332 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29333 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29334 | goodycom_user | localhost | goodycom_db | Sleep | 0 | | |
| 29335 | goodycom_user | localhost | goodycom_db | Sleep | 0 | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
从这里可能会注意到,所有睡眠时间都低于10,如果我的网站中没有其他用户没有查看内容,我就无法设置为终止。 (出于测试目的,我已禁用所有登录功能等等,只留下查看文章,如果我杀死进程,后端的某些计算也会被杀死)
这是我的mysql查询
public function getArticle($article_id){
$query = $this->db->query("SELECT * FROM article where article_id = '" . (int)$article_id. "'");
return $query->row;
}
public function getArticleCategories(){
$query = $this->db->query("SELECT * FROM article_category ORDER BY name asc");
return $query->rows;
}
和db查询类..
final class MySQLi {
private $link;
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->link = new \mysqli($hostname, $username, $password, $database, $port);
if ($this->link->connect_error) {
trigger_error('Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
exit();
}
$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");
}
public function query($sql) {
$query = $this->link->query($sql);
if (!$this->link->errno) {
if ($query instanceof \mysqli_result) {
$data = array();
while ($row = $query->fetch_assoc()) {
$data[] = $row;
}
$result = new \stdClass();
$result->num_rows = $query->num_rows;
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
$query->close();
return $result;
} else {
return true;
}
} else {
trigger_error('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
}
}
public function escape($value) {
return $this->link->real_escape_string($value);
}
public function countAffected() {
return $this->link->affected_rows;
}
public function getLastId() {
return $this->link->insert_id;
}
public function __destruct() {
$this->link->close();
}
}
仍然是opencart的原始版本。
我的网络人员建议我安装litespeed并替换apache来克服这个问题。万岁〜安装了15天试用litespeed后,我的网站终于顺利进行了。 但几分钟后又出现了问题,我启用了登录功能,我注意到所有登录的用户都可以查看其他用户的信息,因为缓存或我不知道...最后我得到了我的网络人员禁用用户登录的缓存,但您猜测...用户的图像管理器(每个用户都有自己的目录,其他用户无法访问)混淆..几秒钟我正在观看& #34; A&#34;的目录......几秒钟后,当我刷新时,它会跳转到&#34; B&#34;的目录。最后,我使用cookie来绕过仍然被litespeed缓存的user_id .. 而现在..今天,网站再次下降......我的老板要求我能够修改脚本以帮助一些人......仍在进行研究......但仍然没有找到帮助.. 对不起破碎的英语..希望这里有人能够提供帮助..
谢谢..