amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with receiving all rows

sallsabil opened this issue · comments

Hello
My table has 3504 rows.
When I use this code:

	function resultToArray($result) {
    $rows = array();
    while($row = mysqli_fetch_assoc($result)) {
        $rows[] = $row;
    }
    return $rows;
	}
	
	function GetMyConnectionGroup() {
		$servername = 'localhost';
		$username = 'root';
		$password = '******';
		$dbname = 'dbn';
		global $g_link;
		if ($g_link) return $g_link;
		$g_link = new mysqli($servername, $username, $password, $dbname) or die('Could not connect to server.');
		return $g_link;
		}
	
		$res = mysqli_query(GetMyConnectionGroup() , "SELECT * FROM groups ORDER BY id");
		$rows = resultToArray($res);
		mysqli_free_result($res);

I can receive all of 3504 rows
But when I use this code:

function MGSC($code='', $m=0) {
	global $row;
	global $db;
\Amp\Loop::run(function() use ($code, $row, $db, $m) {
	global $row;
	global $db;
	if($code) {
    if(!$db) $db = Amp\Mysql\pool("host=localhost user=root password=***** db=dbn");
    
	$type = explode(' ', $code, 2);
	$type[0] = strtolower($type[0]);
    $result = yield $db->query($code);
	if($type[0] == 'select') {
	$row = [];
    if($m === 0) {
    while (yield $result->advance()) {
        $row = $result->getCurrent();
    }
	}
	elseif($m === 1) {
    while (yield $result->advance()) {
        $row[] = $result->getCurrent();
    }
	}
	return $row;
	}
	else {
	return $result;
	}
	}
	else {
    if($db) $db->close();
	}
});
	if($code) {if($row) return $row; elseif(isset($result)) return $result;}
		}

$rows = MGSC("SELECT * FROM groups ORDER BY id", 1);

I mostly receive just 4 rows and some times 25 rows.
Also these errors:

2018-02-07T16:34:01.942293Z 215 [Note] Aborted connection 215 to db: 'dbn' user: 'root' host: 'localhost' (Got an error writing communication packets)

2018-02-07T15:48:02.011128Z 169 [Note] Aborted connection 169 to db: 'dbn' user: 'root' host: 'localhost' (Got an error reading communication packets)

How can I receive all rows ?
What is the problem ?

I'm waiting for you.
If there is no solution Please tell me to switch to the last one.
Thank you
@trowski
@bwoebi

I cannot reproduce that problem locally. May you please set const MYSQL_DEBUG = true; and dump me the data, so that I can replay and debug your connection?

Thanks :-)

I sent you the error:

2018-02-07T16:34:01.942293Z 215 [Note] Aborted connection 215 to db: 'dbn' user: 'root' host: 'localhost' (Got an error writing communication packets)

2018-02-07T15:48:02.011128Z 169 [Note] Aborted connection 169 to db: 'dbn' user: 'root' host: 'localhost' (Got an error reading communication packets)

There is not any other error

I mean within your script. with define("MYSQL_DEBUG", true); it should dump all the raw protocol data to the stderr of your script.

I did what you said but I received nothing other than:

2018-02-12T09:00:01.855322Z 6888 [Note] Aborted connection 6888 to db: 'groupbots' user: 'root' host: 'localhost' (Got an error reading communication packets)

I think the problem is from your project

Am I right ?

@sallsabil We may have a bug in our protocol implementation, but we cannot reproduce it ourselves. Please add const MYSQL_DEBUG = true; to your script, perhaps right after the autoload script is included. This will cause information about the raw protocol to be written to STDERR. If you're using a web SAPI, you may need to check the error log for this information, otherwise it should just be written to the console.

<?php
	$start = microtime(true);
	set_time_limit(62);
	require "/root/vendor/autoload.php";
	const MYSQL_DEBUG = true;
	require __DIR__ . '/classes/setexpf.php';
	$setexpf = new setexpf();
	
	$rows = $setexpf->MGSC("SELECT * FROM groups ORDER BY id", 1);
	echo count($rows);

I use ubuntu 16.04 but in:
/var/log/mysql/error.log
I don't find anything other than the errors I sent in the last comments.

Are you using the CLI version of php?

yes

@sallsabil Please be sure assertions are enabled, as the debug code is wrapped with assert().

I avtivated assert() in php.ini file but no difference

Why can't you reproduce ?

How I understand my mysql doesn't support mysql_debug

It's a constant you set in your client code (PHP), it has nothing to do with the server. You will see the log in the error log of your HTTP server, not the MySQL server.

https://dev.mysql.com/doc/refman/5.7/en/dbug-package.html :
The MySQL server and most MySQL clients are compiled with the DBUG package originally created by Fred Fish. When you have configured MySQL for debugging, this package makes it possible to get a trace file of what the program is doing. See Section 28.5.1.2, “Creating Trace Files”.

you must have a mysqld that has been compiled with debugging support. You can check this by executing mysqld -V. If the version number ends with -debug, it is compiled with support for trace files.

My result of this command

mysqld -V

mysqld Ver 5.7.20-0ubuntu0.16.04.1 for Linux on x86_64 ((Ubuntu))

Not any -debug end.

@sallsabil This client completely re-implements the MySQL protocol and doesn't make use of any other implementation for that.

Could you extract your code into a command line script that's easily runnable by others and provide a dump of your database table (with dummy data if applicable)?

Thanks, but I guess we need more information to reproduce this behavior. Please provide either a Docker setup that reproduces the behavior or provide the debug log we requested. I'll close this issue as it hasn't been updated. We can always re-open the issue in case the requested information is provided.

commented

@kelunik Than I'll try to help with this.

https://github.com/valVk/amph-mysql

Here is in table is 565529 rows

but in fact I can get only first 92 rows.