|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-31 07:59 UTC] 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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 12:00:02 2025 UTC |
The manual page for pg_connection_busy() states: "If pg_get_result() is used on the connection, it will be blocked." How can the query finish during the usleep() if pg_get_result() blocked while the query was still executing? It should have been finished already. If this is in fact "expected behavior" then the manual is wrong and should be changed to reflect what actually happens. Demonstrating the same bug with no usleep(): #!/usr/local/src/php5/php-5.4.0/sapi/cli/php <?php $connStr = sprintf("host=%s dbname=%s user=%s password=%s", 'localhost', 'testlevi', 'levi', 'levi'); ($dbconn = pg_connect($connStr)) or die("Could not connect"); pg_send_query($dbconn, 'i am a syntax error;'); pg_get_result($dbconn); if (pg_connection_busy($dbconn)) { echo "This should be impossible\n"; } ?> 100% of the time this prints "This should be impossible". PHP 5.4, PGSQL 8.3