Bug #65015 [Asn->Csd]: pg_send_query does not flush send buffer
| From: | yohgaki@php.net | Date: | Wed, 26 Jun 2013 07:29:12 +0000 |
| Subject: | Bug #65015 [Asn->Csd]: pg_send_query does not flush send buffer | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179834@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65015&edit=1
ID: 65015
Updated by: yohgaki@php.net
Reported by: adam at vektah dot net
Summary: pg_send_query does not flush send buffer
-Status: Assigned
+Status: Closed
Type: Bug
Package: PostgreSQL related
Operating System: Linux
PHP Version: 5.4.16
Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of yohgaki
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6c8cef3ca49a11228d4dcd188170b943e03c3972
Log: Fixed bug #65015 (pg_send_query does not flush send buffer) patch submitted by: adam at vektah
dot net
Previous Comments:
------------------------------------------------------------------------
[2013-06-26 06:15:34] yohgaki@php.net
Thanks for reporting. I'll commit this fix.
------------------------------------------------------------------------
[2013-06-25 06:32:39] adam at vektah dot net
Updated summary.
------------------------------------------------------------------------
[2013-06-12 03:05:50] adam at vektah dot net
Description:
------------
When sending asynchronous postgres queries using pg_send_query() a notice will
be raised for large queries:
PHP Notice: pg_send_query(): Cannot set connection to blocking mode in
longquery.php on line 6
This only seems to happen on databases NOT hosted on the local machine.
pg_send_query() roughly does:
PQ_SETNONBLOCKING(1)
PQsendQuery()
PQ_SETNONBLOCKING(0)
PQ_SETNONBLOCKING will do this towards the end:
if (pqFlush(conn))
return -1;
and fail raising the notice if the connection still has data left in the send
buffer.
http://www.postgresql.org/docs/8.3/static/libpq-async.html
mentions that:
After sending any command or data on a non-blocking connection, call PQflush. If
it returns 1, wait for the socket to be write-ready and call it again; repeat
until it returns 0. Once PQflush returns 0, wait for the socket to be read-ready
and then read the response as described above.
The attached patch adds a loop that waits for the buffer to empty before calling
PQ_SETNONBLOCKING(0), and raises a notice on any errors.
PHP Versions tested:
- 5.4.9 (ubuntu package)
- 5.4.13 (source)
- 5.4.16 (source)
Postgres configurations tested:
- 9.1.9 client with 2.2.4 server
- 9.2.4 client and server
Operating systems tested:
- Ubuntu 13.04
- Centos 6
Test script:
---------------
$len = 100000; // This may need to be increased, depending on db server.
$sql = "select 1" . str_repeat(' ', $len - 8);
$con = pg_connect('host=db-host.example.com dbname=postgres user=postgres
password=password');
pg_send_query($con, $sql);
pg_get_result($con);
Expected result:
----------------
The query should run, no notices should be rasied and the connection should be
put back into blocking mode again.
Actual result:
--------------
PHP Notice: pg_send_query(): Cannot set connection to blocking mode in
longquery.php on line 6
PHP Stack trace:
PHP 1. {main}() longquery.php:0
PHP 2. pg_send_query() longquery.php:6
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65015&edit=1