|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32774 stdin handling confusion in COPY
Submitted: 2005-04-20 00:13 UTC Modified: 2005-06-27 08:43 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: volkan dot yazici at gmail dot com Assigned:
Status: Wont fix Package: PostgreSQL related
PHP Version: 5.0.3 OS: Linux 2.6.11
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: volkan dot yazici at gmail dot com
New email:
PHP Version: OS:


 [2005-04-20 00:13 UTC] volkan dot yazici at gmail dot com
There seems to be a confusion in handling stdin between PostgreSQL and PHP.

Reproduce code:
$conn = pg_connect("user=knt dbname=template1")
        or die("Connection failed!\n");

print "Starting query...\n";
$res = pg_query("COPY example_table FROM stdin");

 * If I'd not use a pg_end_copy() call just after "COPY FROM
 * stdin" query, script flow will never pass through this
 * line and stuck here with a 100% CPU usage.

if ( pg_result_status($res) != PGSQL_COPY_IN )
    die("Unexpected result status!\n");

print "At last!\n";

 * The same of this script
 * [] written
 * in C (with same libpq calls) works fine.

Expected result:
shell$ php example-copy.php
Starting query...
At last!
shell$ _

Actual result:
shell$ php example-copy.php
Starting query...

# It enters to an endless loop with a 100% CPU usage.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-26 19:18 UTC]
Please try using this CVS snapshot:
For Windows:

 [2005-06-27 08:22 UTC]
I don't think there's any way to fix this with the current
structure of PHP. There's no construct to pass control of
php://stdin to the pg library.
 [2005-06-27 08:43 UTC]
To clarify:

If you're expecting PHP to watch php://stdin for data,
detect lines, call pg_put_line(), and detect "\n\.\n" and
call pg_end_copy(), I think it's safe to classify this as
"Won't Fix".

If you're simply wondering why PHP is hanging on the small
script given below, it's because you didn't pg_end_copy().
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 22 17:03:41 2021 UTC