运行使用php运行MySQL查询的奇怪错误:
PHP Warning: mysqli_query(): Premature end of data (mysqlnd_wireprotocol.c:967) in /ours/scripts/update-trending.php on line 97
PHP Warning: mysqli_query(): EOF packet 1 bytes shorter than expected in /ours/scripts/update-trending.php on line 97
查询很简单,单独运行时工作正常:
mysql> select ifnull(count(nid),0) from likes where nid=18578;
+----------------------+
| ifnull(count(nid),0) |
+----------------------+
| 0 |
+----------------------+
1 row in set (0.03 sec)
在for循环期间出现错误,循环通过nid值(1-19000)。它适用于98%的查询,但有时随机失败并出现上述错误。这一切都发生在一个mysqli连接上,因此它不是身份验证问题。
正在使用的实际代码(在for循环中):
$qLikesSQL='select ifnull(count(nid),0) from likes where nid=' . $thisNID;
if ($qLikesResulter=mysqli_query($link,$qLikesSQL)) {
if ($qLikesRow=mysqli_fetch_assoc($qLikesResulter))
{
$qLikes=$qLikesRow['ifnull(count(nid),0)'];
}
mysqli_free_result($qLikesResulter);
} else echo "MySQL query failed: $qLikesSQL\n";
PHP版本:
PHP 7.0.28-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.28-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
MySQL版本:
AWS RDS Instance - Aurora MySQL 5.7.12
正在生成MySQL错误日志:
2018-03-27T13:27:52.576966Z 7276977 [Note] Aborted connection 7276977 to db: '***snip***' user: '***snip***' host: '***snip***' (Got an error reading communication packets)
更新:我将数据库从RDS Aurora MySQL(5.7.12)实例移动到RDS MySQL(5.7.16)实例,问题消失了。所以这可能是Aurora特有的。