Re: [INTERFACES] Duplicate INSERTS into pgsql table via PHP

From: David Osborne <David(dot)Osborne(at)nottingham(dot)ac(dot)uk>
To: Jason Earl <jearl(at)box100(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] Duplicate INSERTS into pgsql table via PHP
Date: 1999-12-14 14:23:59
Message-ID: 2422.945181439@unix.ccc.nottingham.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

jearl(at)box100(dot)com said:
> I am running a very similiar setup (modified RedHat 5.2, Apache 1.3.9,
> PHP 3.0.12, PostgreSQL 6.5.2) and I cut and pasted your example into
> tester.php3 and created a database cczdao and a table mytest as:
>
> create table mytest(foo int, bar text);
>
> And it worked just fine.

Thanks for trying to reproduce my problem.

> Perhaps there is something else that is going
> wrong? Could you perhaps give a little more info. Are there any
> redirects happening

No 301 entries appear in the Apache access log.

> does the same script generate the form and insert
> the data into the table?

No, in the case of the form page I started working on, the PHP page
which does the insert is defined as an action: <FORM
ACTION="referral_create.php3">

But in the test I gave as an example in my message, no form is
involved, just a page whose embedded PHP code opens the database
connection, does the insert and closes the connection -- I've appended
it below. Yet it still gets requested twice when browsed by Netscape.
The most puzzling thing is why the page is only requested once when
browsed using Lynx.

Here's what I mean, from the access log. The connections from
128.243.101.85 are using Lynx, those from 128.243.40.194 are using
Netscape 4.5. The requests from Lynx for the pages pgselect.php3 and
pginsert.php3 are each logged once, while requests for the same pages
from Netscape are logged twice. "pgselect.php3" just connects and
executes a select on the table, to show its contents; "pginsert.php3"
is shown below and is the one which executes the insert statement.

128.243.101.85 - - [14/Dec/1999:13:41:53 +0000] "GET /~cczdao HTTP/1.0"
301 336
128.243.101.85 - - [14/Dec/1999:13:41:54 +0000] "GET /~cczdao/
HTTP/1.0" 200 894
128.243.101.85 - - [14/Dec/1999:13:42:00 +0000] "GET /~cczdao/php/
HTTP/1.0" 200 1897
128.243.101.85 - - [14/Dec/1999:13:42:05 +0000] "GET
/~cczdao/php/pgselect.php3 HTTP/1.0" 200 986
128.243.101.85 - - [14/Dec/1999:13:42:16 +0000] "GET
/~cczdao/php/pginsert.php3 HTTP/1.0" 200 142
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /~cczdao/php/
HTTP/1.0" 200 1897
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/back.gif
HTTP/1.0" 200 216
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/blank.gif
HTTP/1.0" 200 148
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/text.gif
HTTP/1.0" 200 229
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/text.gif
HTTP/1.0" 200 229
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:34 +0000] "GET /icons/unknown.gif
HTTP/1.0" 200 245
128.243.40.194 - - [14/Dec/1999:13:42:39 +0000] "GET
/~cczdao/php/pgselect.php3 HTTP/1.0" 200 1020
128.243.40.194 - - [14/Dec/1999:13:42:40 +0000] "GET
/~cczdao/php/pgselect.php3 HTTP/1.0" 200 1020
128.243.40.194 - - [14/Dec/1999:13:42:48 +0000] "GET
/~cczdao/php/pginsert.php3 HTTP/1.0" 200 142
128.243.40.194 - - [14/Dec/1999:13:42:48 +0000] "GET
/~cczdao/php/pginsert.php3 HTTP/1.0" 200 142

I've even run it while watching with a packet sniffer ("snoop" on
Solaris), and can see the host running the browser sending two
successive GETs for the pginsert.php3 page, with the host running
Apache just sending back for each one a "200 OK" response and the page.
No redirects or any other responses from Apache.

I guess it may be a Netscape/Apache/HTTP issue, but it's really
affecting my use of Postgres via PHP, and using the database that way
is the reason I installed it. As I said, all database access via psql
works fine, and all the standard regression tests were passed, so I'm
confident of the Postgres installation.

> Also, I am curious as to why you are not using
> the nifty persistent connection pg_pconnect function?

To keep things simple! If I'm right in thinking that pconnect is used
to improve efficiency, it shouldn't make any difference whether
pg_connect or pg_pconnect is used?

Any ideas of where I should dig deeper to get to the bottom of this?

thanks in advance
David

----------------------
pginsert.php3
-------------
<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<HTML>
<HEAD>
<TITLE>pgsql insertion test</TITLE>
</HEAD>
<BODY BACKGROUND="#FFFFFF">
<H1>pgsql insertion test</H1>
<HR>
<?php
$conn = pg_connect("", "", "", "","cczdao");
$result = pg_exec($conn, "insert into mytest values (444, 'some
text')");
pg_close($conn);
?>
<HR>
</BODY>
</HTML>

Browse pgsql-interfaces by date

  From Date Subject
Next Message Matthew Hagerty 1999-12-14 19:13:04 Backend core dump, Please help, Urgent!
Previous Message postgres 1999-12-14 09:26:47 Re: [GENERAL] Is it safe to INSERT/DELETE during VACUUM?