Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Native client occasionally truncates large result sets #2343

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

PHP Native client occasionally truncates large result sets #2343

monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
bug Something isn't working Client interfaces normal

Comments

@monetdb-team
Copy link

Date: 2010-03-23 08:47:17 +0100
From: Stephen Benz <>
To: clients devs <>
Version: -- development

Last updated: 2010-07-09 13:49:53 +0200

Comment 13149

Date: 2010-03-23 20:47:17 +0100
From: Stephen Benz <>

mapi_read in the native php socket client assumes socket_read is going to actually return the chunk size that's requested. While this does happen in many cases, when there's a large result set or network latency only a portion of that read may happen. This causes a limited number of rows to be returned, and other weird behavior.

Environment:
Linux, CentOS 5
PHP 5.1.6
MonetDB Nov 2009 (but verified the php code hasn't been fixed in Feb 2010)

Reproduction steps:

  1. $res = monetdb_query("select * from largeTable;"); // where largeTable is a table with 500k+ rows, in our case
  2. Notice the result doesn't contain all the rows... the number is variable based on the connection to the db server (we run monetdb on another server, not localhost)

Fix:
in php_mapi.inc (function mapi_read()):
$data = socket_read($socket, $chunk_size);
// can't assume the read is going to give you the actual size you expect
while(strlen($data) < $chunk_size)
{
$data .= socket_read($socket, $chunk_size - strlen($data));
}

and a few lines later:

		if ( ($block = socket_read($socket, $chunk_size)) == FALSE) {
             	        $last_error = socket_strerror(socket_last_error()); 
     	                return FALSE;
                }
		while(strlen($block) < $chunk_size)
		{
			$block .= socket_read($socket, $chunk_size - strlen($block));
		}

Comment 13150

Date: 2010-04-15 15:04:37 +0200
From: @sjoerdmullender

Thanks for the report and the fix.
I checked in a variant of your fix. This should make it into the next release.
Can you check whether my version works?

Comment 13151

Date: 2010-04-15 16:44:15 +0200
From: Stephen Benz <>

Yup! Just tested the new version from CVS and it fixes the issue. Thanks!

Comment 13152

Date: 2010-05-04 09:32:09 +0200
From: Pseudo user for Sourceforge import <>

This bug was previously known as tracker item 2975433 at http://sourceforge.net/support/tracker.php?aid=2975433

Comment 14313

Date: 2010-07-09 13:49:53 +0200
From: @sjoerdmullender

Not adding a test since it requires a larg(ish) database and a slow connection, neither of which is practical in the testweb setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Client interfaces normal
Projects
None yet
Development

No branches or pull requests

2 participants