php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80374 Mysqli warning Packets out of order. Expected 1 received 0
Submitted: 2020-11-16 11:28 UTC Modified: 2023-01-10 16:26 UTC
Votes:9
Avg. Score:4.3 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:6 (75.0%)
From: w2kzx80 at gmail dot com Assigned:
Status: No Feedback Package: MySQLi related
PHP Version: 7.4.12 OS: CentOs
Private report: No CVE-ID: None
 [2020-11-16 11:28 UTC] w2kzx80 at gmail dot com
Description:
------------
Hi
Im using php 7.4.10 and i cant simply upgrade it to 7.4.12 if im not sure it will resolve problem because its production server and situation is unique and its difficult to find another such situations. So for now while i found it im not changing nothing in server configuration till ill find answer.
First of all - this bug happen in some random cases but when it happen in some my part of code - it happen always.
Problem is in creating mysql requests using mysqli library. In some sql statements it creates problems like "Packets out of order. Expected 1 received 0". I noticed that it doesnt depend on mysql configuration because i have many same databases with same access and many same tables with same structure and all is same and all works but some sql statements return this error

ALSO what is very strange - i change sql request with adding one space and it start working. It mean that there is something basic wrong with networking in php

Test script:
---------------
//.... im connecting to db and so on and then
$la=$db->query('SELECT * FROM  `voipe_481`.`labels_auto`');
//here i put additional space between FROM and database name - and it works OK

$la=$db->query('SELECT * FROM `voipe_481`.`labels_auto`');
// here it write Warning and disconnects from server
//PHP Warning:  Packets out of order. Expected 1 received 0. Packet size=1

Expected result:
----------------
both sql requests must work fine

Actual result:
--------------
first sql request works fine, second crashes connection to database
Interesting is that im checking $db->ping before each request and it is ok but after second request it is false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-16 11:33 UTC] nikic@php.net
How reproducible is this issue? Is this something you see every time, or more something that happens rarely and randomly?
 [2020-11-16 15:15 UTC] w2kzx80 at gmail dot com
well - yes its reproducible
if I found some SQL which give this error - this error repeat each time this SQL is used
So i can reproduce it 1000 times if i want but I dont know how to find this SQL - I found one and i know how to check it. But I dont have ideas why exact this SQL statement give me this error..
 [2020-12-04 18:09 UTC] dharman@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: dharman
 [2020-12-04 18:09 UTC] dharman@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

Thanks for the bug report. However, we need more information to be able to reproduce the issue. Currently, we can't reproduce the issue. A lot of factors could cause this problem, and its nature requires that we receive extremely thorough reproducible steps. 
Please let us know:
- Platform (Windows/Linux/Mac)
- MySQL flavor and version e.g. MariaDB 10.4.1
- Whether mysqli was compiled against libmysqlclient or mysqlnd
- Which connection method was used (TCP/IP or socket or named pipe)
- Your table schema. (SHOW CREATE TABLE tbl_name) including charset used for connection and table storage. 
- The character encoding of your file. Are you using UTF-8?
- Are you using utf8mb4 charset? Did you set the charset via `set_charset()` method? 
- HEX dump of the query string producing the error. (There could be a hidden character there)
- HEX dump of the sample data causing the error. 
- Self contained reproducible example. http://sscce.org/ should help you make such an example.

We would love to hear back from you and if possible fix the bug you have reported.
 [2020-12-13 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2020-12-13 08:44 UTC] w2kzx80 at gmail dot com
guys - I wrote You enough. Didnt You read?

- Platform Linux
- MySQL = 
MariaDB [(none)]> STATUS;
--------------
mysql  Ver 15.1 Distrib 5.5.65-MariaDB, for Linux (x86_64) using readline 5.1

SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         5.5.65-MariaDB MariaDB Server
Protocol version:       10
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:               3306

- i use mysqli library. Phpinfo shows mysqli
Client API library version	mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Compression	supported
Command buffer size	4096
Read buffer size	32768
Read timeout	31536000
Collecting statistics	Yes
Collecting memory statistics	No
Tracing	n/a
Loaded plugins	mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
API Extensions	mysqli,pdo_mysql

- Which connection method was used = TCP/IP
- Your table schema. (SHOW CREATE TABLE tbl_name) including charset used for connection and table storage. 
CREATE TABLE `labels_auto` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `label_id` int(11) DEFAULT NULL,
  `atype` char(1) DEFAULT NULL,
  `did` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8"

- The character encoding of your file. Are you using UTF-8?
Yes

- Are you using utf8mb4 charset? Did you set the charset via `set_charset()` method? 
yes i used utf8 in set_charset

- HEX dump of the query string producing the error. (There could be a hidden character there)
I dont understand what You want from me...
this query returns
HEX("SELECT * FROM `voipe_481`.`labels_auto`")
53454C454354202A2046524F4D2060766F6970655F343831602E606C6162656C735F6175746F60

- HEX dump of the sample data causing the error. 
I dont understand.. query doesnt execute - something happen while query is compressed and sent to server and server doesnt recognize it

- Self contained reproducible example. http://sscce.org/ should help you make such an example.
Sorry - i dont have time for it
I get You all the info
 [2020-12-13 21:30 UTC] dharman@php.net
-Status: No Feedback +Status: Open -Assigned To: dharman +Assigned To:
 [2021-07-19 07:30 UTC] info at 4ws-netdesign dot de
We discover the same problem:

Ubuntu 18.04 - PHP 7.4.3 FPM/FastCGI
MySQL:  8.0.25-0ubuntu0.20.04.1 - (Ubuntu) 

Yes it's reproducible: if you have a query producing this error you can repeat as often you want: the warning appears.

We have simple queries produding this error. By adding useless whitespaces in the query you can fix this query - but the problem still exists at other places.

Increasing max_allowed_packet to 2G in my.cnf fixes the problem partially but it still occurs on some places.

Scripts worked fine with PHP 7.2 before. And it's really simple queries like

SELECT * FROM tablename

producing this error (small tables => 0-10 entries)
 [2021-07-19 13:47 UTC] w2kzx80 at gmail dot com
Thats my "solution" in php - but OF COURSE - it is bad solution. But i cant wait till it will be fixed in mysql server so... maybe it will be useful for somebody

$res = $db->query($query);
if (!$res) $res=$db->query(preg_replace('/^([ ]*[^ ]+) (.+)$/uis','$1  $2',$query));

Thats it... It adds one additional space between first word of request and next part
Like
"SELECT * FROM table" -> "SELECT  * FROM table"

Unfortunately i cant detect some logical indications that some query will not be successful. Only this method with retry...
 [2021-08-09 11:02 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-09 11:02 UTC] cmb@php.net
> But i cant wait till it will be fixed in mysql server so...

So is this a bug in MariaDB?  Is there a related bug report?
 [2021-08-09 13:24 UTC] w2kzx80 at gmail dot com
How can i know if it is bug of MariaDB or php?
I didnt develop nor php nor mysql - i just reported which is issue - i guess its something with bytes in compression algorythm between php and mariadb but how can i know if it is php bug or mariadb bug? Most looks like php because i used console mysql utility with same request and didnt receive any error but I dont know how all this works - i think developers of php language must know isnt it?..
 [2021-08-09 13:41 UTC] cmb@php.net
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-08-09 13:41 UTC] cmb@php.net
Okay, so apparently your comment was a "typo".  Anyhow, this bug
report doesn't appear to be actionable, unless you can provide
further information.
 [2023-01-10 16:26 UTC] dharman@php.net
-Status: Open +Status: No Feedback
 [2023-01-10 16:26 UTC] dharman@php.net
Thanks for reporting this. But unfortunately, we still do not know how to reproduce it on our machines. It might something specific to your environment but there could be thousands of different configurations we haven't tried. 

If you tell us how to reproduce this issue ourselves, please reopen the bug report on https://github.com/php/php-src/issues Please check if it is still happening with PHP 8.2 first.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC