473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

persistent postgres connections in PHP

Hello all!

I'm working on a PHP site using Postgres as a back-end. I have an
include at the top of each page that runs the pg_connect function.

I'm implementing some temporary tables, which I understand are
destroyed automatically at the end of the session. It seems to me
that
when I navigate to a new page, or re-load my existing page, I lose my
temporary tables. Is this because I am creating a new session at the
beginning of each page with my pg_connect include?

Also, are temporary tables globally visible, or only within that
session? I mean, can one user see another user's temporary tables?

Jun 15 '07 #1
5 2744
C.
On 15 Jun, 15:53, lawp...@gmail.com wrote:
I'm implementing some temporary tables, which I understand are
destroyed automatically at the end of the session. It seems to me
that
when I navigate to a new page, or re-load my existing page, I lose my
temporary tables. Is this because I am creating a new session at the
beginning of each page with my pg_connect include?

I'm not specifically familiar with PostgreSQL, but persistent
connections are not going to solve your problem - connections are held
in a pool and allocated on a first come, first served basis - there's
no reason to expect that your PHP session will connect back to the
same DBMS session.
Also, are temporary tables globally visible, or only within that
session? I mean, can one user see another user's temporary tables?
They should only be visible within the current DBMS session - whether
persistent connections preserve the DBMS session....I don't know, but
(see above) the question is somewhat academic.

One solution would be to create a real table using a session
identifier (e.g. PHP session id) in the name. Of course you'd need to
handle the clean up from your own session handler.

HTH

C.

Jun 15 '07 #2
On Jun 15, 5:15 pm, "C." <colin.mckin...@gmail.comwrote:
On 15 Jun, 15:53, lawp...@gmail.com wrote:
I'm implementing some temporary tables, which I understand are
destroyed automatically at the end of the session. It seems to me
that
when I navigate to a new page, or re-load my existing page, I lose my
temporary tables. Is this because I am creating a new session at the
beginning of each page with my pg_connect include?

I'm not specifically familiar with PostgreSQL, but persistent
connections are not going to solve your problem - connections are held
in a pool and allocated on a first come, first served basis - there's
no reason to expect that your PHP session will connect back to the
same DBMS session.
I'm a little confused then. In my MySQL sites, I have an include at
the beginning of each page that connects to the MySQL server. I have
not had a problem connecting to temporary tables that I created on
other pages, which means that my access to them has persisted over
several 'mysql_connects'. Have I just been lucky that I maintained the
connection/session that had my temporary tables when I got a
connection from the pool? I just always happened to get the one that I
wanted?

However, in this postgres site that I am developing, I seem to lose my
connection to the temporary tables after I traverse another
pg_connect. I don't know if this is part of my php.ini, or what. But
it does seem to show different behavior between mysql_connect and
pg_connect.
Jun 17 '07 #3
C.
On 17 Jun, 15:46, lawp...@gmail.com wrote:
Have I just been lucky that I maintained the
connection/session that had my temporary tables when I got a
connection from the pool? I just always happened to get the one that I
wanted?
Yes
RTFM:
http://dev.mysql.com/doc/refman/5.0/...ate-table.html
and
http://www.php.net/manual/en/feature...onnections.php

C.

Jun 17 '07 #4
On Jun 17, 3:03 pm, "C." <colin.mckin...@gmail.comwrote:
On 17 Jun, 15:46, lawp...@gmail.com wrote:
Have I just been lucky that I maintained the
connection/session that had my temporary tables when I got a
connection from the pool? I just always happened to get the one that I
wanted?

Yes
RTFM:http://dev.mysql.com/doc/refman/5.0/...ate-table.html
andhttp://www.php.net/manual/en/features.persistent-connections.php

C.
Then why would persistent connections seem to be failing in this case
with postgres?

Jun 18 '07 #5
C.
On 18 Jun, 14:41, lawp...@gmail.com wrote:
On Jun 17, 3:03 pm, "C." <colin.mckin...@gmail.comwrote:

Then why would persistent connections seem to be failing in this case
with postgres?
This is just conjecture - but maybe mysql uses first come/first served
while PG does round-robin.

Regardless, the way you are using persistent connections is
innapropriate.

C.
Jun 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an...
2
by: Steve Jenkins | last post by:
Wonder if anyone can help. So, I've read: >> http://uk2.php.net/function.mysql-pconnect >> http://uk2.php.net/manual/en/features.persistent-connections.php Can one seriously see persistent...
3
by: Derek Fountain | last post by:
For a low-ish traffic website that is doing the simple "build pages from HTML templates and info in a database" kind of thing, do the wise folks in this newsgroup advocate connecting and...
5
by: Felix E. Klee | last post by:
I've set up a PHP web application where users can log in and open a connection to a NNTP-server. There is a *one-to-one* relationship between sessions and NNTP-connections (i.e. exactly one...
16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
6
by: David Rasmussen | last post by:
I use urllib2 to do some simple HTTP communication with a web server. In one "session", I do maybe 10-15 requests. It seems that urllib2 opens op a connection every time I do a request. Can I...
6
by: Prabu Subroto | last post by:
Dear my friends... Usually I use MySQL. Now I have to migrate my database from MySQL to Postgres. I have created a database successfully with "creatdb" and a user account successfully. But...
3
by: Randall Nortman | last post by:
I assume I'm not the first person to have encountered this, but I couldn't find anything in the FAQ or on the mailing lists recently. My apologies if this is already documented somewhere... My...
9
by: mel | last post by:
Hi all, I need a persistent TCP connection with my web server over page reloads. This means that, even if the user goes to a different page (in my domain), I want to keep a TCP connection...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.