Edit report at https://bugs.php.net/bug.php?id=63365&edit=1
ID: 63365
User updated by: chris at ctgameinfo dot com
Reported by: chris at ctgameinfo dot com
Summary: pg_send_query() blocks on queries to other
connections.
Status: Not a bug
Type: Bug
Package: PostgreSQL related
Operating System: FreeBSD (probably irrevelant)
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
It should be able to throw away the variable without closing the connection
(much
like calling pg_connect without assigning to a variable leaves it open). I
realize doing this could cause a memory leak for the duration of the script,
but
as long as the implicit close at script termination still happens it should be
fine.
In any case, please update the documentation to make this more clear since
blocking on variable assignment is not something one normally expects to happen.
Previous Comments:
------------------------------------------------------------------------
[2013-06-05 13:52:46] [email protected]
Sorry, hit submit too early. By overwriting the connection variable, you force
the old connection to be closed. In order to do that, PHP is waiting for the
query to complete and discard its output.
------------------------------------------------------------------------
[2013-06-05 13:48:32] [email protected]
This won't block:
<?php
for($i=1;$i<=10;$i++)
{
echo "Interation $i\n";
$dbconn[$i] = pg_connect("dbname=postgres", PGSQL_CONNECT_FORCE_NEW);
// Will block in the second loop interation
pg_send_query($dbconn[$i], "select pg_sleep(5)");
echo "Last error: '".pg_last_error($dbconn[$i])."'\n";
}
?>
So the issue only happens when you "overwrite" an existing connection
------------------------------------------------------------------------
[2012-10-28 16:24:28] chris at ctgameinfo dot com
Modified test script with requested pg_last_error output.
-------
<?php
for($i=1;$i<=10;$i++)
{
echo "Interation $i\n";
$dbconn = pg_connect("user=cstdenis dbname=postgres",
PGSQL_CONNECT_FORCE_NEW);
// Will block in the second loop interation
pg_send_query($dbconn, "select pg_sleep(5);");
echo "Last error: '".pg_last_error($dbconn)."'\n";
}
?>
Output:
-------
Interation 1
Last error: ''
Interation 2
Last error: ''
Interation 3
Last error: ''
Interation 4
Last error: ''
Interation 5
Last error: ''
Interation 6
Last error: ''
Interation 7
Last error: ''
Interation 8
Last error: ''
Interation 9
Last error: ''
Interation 10
Last error: ''
------------------------------------------------------------------------
[2012-10-28 13:57:36] [email protected]
Please, check out the return from pg_last_error($dbconn); after the
pg_send_query() call and post the result in there.
------------------------------------------------------------------------
[2012-10-25 20:58:13] chris at ctgameinfo dot com
Description:
------------
If I open a connection and send a long running query with pg_send_query, then
open a second connection and try to send a query over the second connection
with
pg_send_query it will block on the first connection's query not being complete
Test script:
---------------
<?php
for($i=1;$i<=10;$i++)
{
echo "Interation $i\n";
$dbconn = pg_connect("user=pgsql dbname=postgres",
PGSQL_CONNECT_FORCE_NEW);
// Will block in the second loop interation
pg_send_query($dbconn, "select pg_sleep(5);");
}
?>
Expected result:
----------------
pg_send_query should only block on incomplete queries on the same connection.
Actual result:
--------------
pg_send_query blocks on incomplete queries on any connection.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63365&edit=1