Edit report at https://bugs.php.net/bug.php?id=52750&edit=1
ID: 52750 Updated by: [email protected] Reported by: levi at alliancesoftware dot com dot au Summary: pg_get_result does not block if an error occurred -Status: Open +Status: Not a bug Type: Bug Package: PostgreSQL related Operating System: Linux (FC10) PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: This isn't a bug. The reason why pg_connection_busy() returns false is PostgreSQL actually finished query during usleep(). If query is not executing, pg_connection_busy() returns false. Therefore, this is expected behavior. Previous Comments: ------------------------------------------------------------------------ [2010-08-31 07:59:43] levi at alliancesoftware dot com dot au Description: ------------ Continuation of http://bugs.php.net/bug.php?id=36469 -- it won't let me reopen the bug (too old?) but it still exists. (It seems to be worse on modern hardware since there are multiple CPUs and the php process never has to yield to the postgres process) The manual says that pg_get_result() will block until results are ready, but if there was any sort of error (syntax error or query error, eg table does not exist) then pg_get_result() will return immediately. This causes problems since the next command you try to run may fail because the previous command hasn't actually finished. Test script: --------------- #!/usr/local/src/php5/php-5.3.3/sapi/cli/php <?php if (!isset($_SERVER['argv'][1])) { echo "Missing sleep time\n"; exit(1); } $sleepTime = $_SERVER['argv'][1]; $connStr = sprintf("host=%s dbname=%s user=%s password=%s", 'localhost', 'testlevi', 'levi', 'levi'); ($dbconn = pg_connect($connStr)) or die("Could not connect"); $i = 0; do { pg_send_query($dbconn, 'i am a syntax error;'); pg_get_result($dbconn); usleep($sleepTime); $i++; } while (!pg_connection_busy($dbconn)); echo "got a busy signal after $i commands"; ?> (There are 2 alternate scripts in the previous bug report that effectively show the same thing) Expected result: ---------------- Should loop forever Actual result: -------------- ./test.php 0 got a busy signal after 1 commands ./test.php 10 got a busy signal after 3033 commands ./test.php 1000 (loops forever) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=52750&edit=1
