Bug #65015 [NEW]: pg_send_query
From: adam at vektah dot net
Operating system: Linux
PHP version: 5.4.16
Package: PostgreSQL related
Bug Type: Bug
Bug description:pg_send_query
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 bug report at https://bugs.php.net/bug.php?id=65015&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65015&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65015&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65015&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65015&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65015&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65015&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65015&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65015&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65015&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65015&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65015&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65015&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65015&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65015&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65015&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65015&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65015&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65015&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65015&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65015&r=mysqlcfg
Thread (4 messages)
- adam at vektah dot net