pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedmaybe Offtopic : PostgreSQL & PHP ?
6+ messages / 5 participants
[nested] [flat]
* maybe Offtopic : PostgreSQL & PHP ?
@ 2001-04-18 09:33 Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Re: maybe Offtopic : PostgreSQL & PHP ? Keith Wong <keith@e-magine.com.au>
0 siblings, 1 reply; 6+ messages in thread
From: Picard, Cyril @ 2001-04-18 09:33 UTC (permalink / raw)
To: pgsql-sql
Hi all, sorry for the maybe offtopic questions, but I did not get any answer
from the PHP ML.
I would like to query a postgresql db with the php language.
Today I wrote a script (connectandquery.php) performing the following :
- connect to the DB : $conn = pg_Connect("dbname = foo");
- execute the query : $res = pg_Exec($conn,"SELECT * from BAR");
But I would like to write this in two scripts :
- connect.php : $conn = pg_Connect("dbname = foo");
- query.php : $res = pg_Exec($conn,"SELECT * from BAR");
but I don't know how to get the $conn variable (defined in connect.php) in
the script query.php.
Any idea is welcome !
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: maybe Offtopic : PostgreSQL & PHP ?
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
@ 2001-04-18 12:35 ` Keith Wong <keith@e-magine.com.au>
2001-04-18 13:34 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
0 siblings, 1 reply; 6+ messages in thread
From: Keith Wong @ 2001-04-18 12:35 UTC (permalink / raw)
To: Picard, Cyril <cyril.picard@eads-dsn.com>; pgsql-sql
Not quite sure how your code is organised...
but you could access the variable $conn by including "connect.php" into the
"query.php" script.
Otherwise, you will need to use persistent connections... which can be
achieved via pg_pconnect...
a persistent connection will instead of creating a new database connection
each time.. it will try to use
an existing connection that is no longer being used (persistent connections
do tend to have a lot of quirks tho)
Keith
At 11:33 AM 18/04/2001 +0200, Picard, Cyril wrote:
>Hi all, sorry for the maybe offtopic questions, but I did not get any answer
>from the PHP ML.
>
>I would like to query a postgresql db with the php language.
>Today I wrote a script (connectandquery.php) performing the following :
>- connect to the DB : $conn = pg_Connect("dbname = foo");
>- execute the query : $res = pg_Exec($conn,"SELECT * from BAR");
>
>
>But I would like to write this in two scripts :
>- connect.php : $conn = pg_Connect("dbname = foo");
>- query.php : $res = pg_Exec($conn,"SELECT * from BAR");
>
>but I don't know how to get the $conn variable (defined in connect.php) in
>the script query.php.
>
>Any idea is welcome !
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: maybe Offtopic : PostgreSQL & PHP ?
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Re: maybe Offtopic : PostgreSQL & PHP ? Keith Wong <keith@e-magine.com.au>
@ 2001-04-18 13:34 ` Roberto Mello <rmello@cc.usu.edu>
2001-04-18 14:54 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
0 siblings, 1 reply; 6+ messages in thread
From: Roberto Mello @ 2001-04-18 13:34 UTC (permalink / raw)
To: Keith Wong <keith@e-magine.com.au>; +Cc: Picard, Cyril <cyril.picard@eads-dsn.com>; pgsql-sql
On Wed, Apr 18, 2001 at 10:35:09PM +1000, Keith Wong wrote:
> an existing connection that is no longer being used (persistent connections
> do tend to have a lot of quirks tho)
What quirks? I am developing a PHP now and using persistant
connections. Coming from the AOLserver/OpenNSD world -- where ALL
connections are persistant, pooled, and dstributed among threads -- I'd be
interested in knowing the quirks of persistant connections in PHP.
-Roberto
--
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
Roberto Mello - Computer Science, USU - http://www.brasileiro.net
http://www.sdl.usu.edu - Space Dynamics Lab, Developer
I may be fat, but you are ugly, and I can diet...
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: maybe Offtopic : PostgreSQL & PHP ?
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Re: maybe Offtopic : PostgreSQL & PHP ? Keith Wong <keith@e-magine.com.au>
2001-04-18 13:34 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
@ 2001-04-18 14:54 ` Roberto Mello <rmello@cc.usu.edu>
2001-04-18 15:37 ` Re: maybe Offtopic : PostgreSQL & PHP ? Josh Berkus <josh@agliodbs.com>
2001-04-18 18:12 ` Re: maybe Offtopic : PostgreSQL & PHP ? Mathijs Brands <mathijs@ilse.nl>
0 siblings, 2 replies; 6+ messages in thread
From: Roberto Mello @ 2001-04-18 14:54 UTC (permalink / raw)
To: Mathijs Brands <mathijs@ilse.nl>; +Cc: pgsql-sql
On Wed, Apr 18, 2001 at 04:44:36PM +0200, Mathijs Brands wrote:
> I've written several applications with Apache/PHP. At first I was using
> persistant connections, but I was soon forced to revert to normal db
> connects. The problem is the number of connections opened. If you have
> 50 Apache processes and 5 different databases, it is highly likely that
> you will end up (if you leave your application running long enough) with
> 250 persistant db links; not something pgsql really likes, unless you
> configure it to correctly handle large numbers of db links. Apache/PHP
> doesn't provide you with some way to pool connections :(
Ah, I see the problem. When you mentioned there were problems I
thought you were talking about the connections themselves.
I am using PHP 4 under AOLserver/OpenNSD, which has been fully
threaded from scratch (1994) so I hope this won't be much of an issue (but
then PHP 4 still has threading problems AFAIK).
Not using persistant connections is just too slow for me. It's
instantaneous for AOLserver to generate a page, when the same page with the
connection overhead in PHP takes A LOT longer.
-Roberto
--
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
Roberto Mello - Computer Science, USU - http://www.brasileiro.net
http://www.sdl.usu.edu - Space Dynamics Lab, Developer
Tetris tagline: @@ o@o oooo @oo oo@
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: maybe Offtopic : PostgreSQL & PHP ?
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Re: maybe Offtopic : PostgreSQL & PHP ? Keith Wong <keith@e-magine.com.au>
2001-04-18 13:34 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
2001-04-18 14:54 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
@ 2001-04-18 15:37 ` Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 6+ messages in thread
From: Josh Berkus @ 2001-04-18 15:37 UTC (permalink / raw)
To: pgsql-sql
Folks,
Not to be a list-nazi or anything, but can we move this discussion to
the PHP list? These issues are already part of the PHP list archives.
If anyone is interested in Postgres-PHP topics, the PHP list is still
quite low-traffic.
-Josh Berkus
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: maybe Offtopic : PostgreSQL & PHP ?
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Re: maybe Offtopic : PostgreSQL & PHP ? Keith Wong <keith@e-magine.com.au>
2001-04-18 13:34 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
2001-04-18 14:54 ` Re: maybe Offtopic : PostgreSQL & PHP ? Roberto Mello <rmello@cc.usu.edu>
@ 2001-04-18 18:12 ` Mathijs Brands <mathijs@ilse.nl>
1 sibling, 0 replies; 6+ messages in thread
From: Mathijs Brands @ 2001-04-18 18:12 UTC (permalink / raw)
To: Roberto Mello <rmello@cc.usu.edu>; +Cc: pgsql-sql
On Wed, Apr 18, 2001 at 08:54:24AM -0600, Roberto Mello allegedly wrote:
> Ah, I see the problem. When you mentioned there were problems I
> thought you were talking about the connections themselves.
> I am using PHP 4 under AOLserver/OpenNSD, which has been fully
> threaded from scratch (1994) so I hope this won't be much of an issue (but
> then PHP 4 still has threading problems AFAIK).
> Not using persistant connections is just too slow for me. It's
> instantaneous for AOLserver to generate a page, when the same page with the
> connection overhead in PHP takes A LOT longer.
So how does AOLserver/PHP handle connections then? Is AOLserver managing
(pooling) connections for PHP or something like that (like websphere and
nas do for Java programs)? A big problem (in my opinion) with Apache is
that you cannot limit the number of Apache processes that acquire
database links. For instance, it would be great if I could instruct
Apache to direct PHP request to a maximum of, say, 20 dedicated
processes. As it stands now, your best bet is probably a two step
approach; have a reverse proxy (such as a very lean apache installation)
or some other proxy (such as a loadbalancer) redirect requests to
multiple webservers, some of which have the pgsql PHP module.
Another approach we've used for our own development environment (DBL) is
using a SQL proxy. We've placed a proxy between the webservers and the
databases. It provides multiplexing of connections and caching of
queries. Fail-over or load balancing is not implemented, but not that
difficult in our case, since our webservers do not directly update the
databases themselves. There's an Open Source product that provides
similar functionality (I think it's called SQL Relay or something
similar). There maybe be some commercial offerings for Open Source
databases such as pgsql and mysql, but I haven't looked into that.
Of course, having lots of db connections may not be necessary. We're
running one of the bigger news sites in Holland. It's implemented using
Java servlets, run without big-gun application servers such as WAS or
NAS (just the M5 webserver) and it uses PostgreSQL 7.0 for it's data
storage (both images and xml). It runs on a fairly small server and is
able to sustain more than 600,000 hits daily without breaking out in a
sweat. Of course, caching is a big thing, since actually generating a
page may take a second or more, but due to the way we maintain and prime
the cache, the users normally don't notice. However, restarting the
(web) server is a bitch though, since it usually takes 10-15 minutes to
build up a cache big enough to be able to serve most request directly
from the cache. It may be a fairly common setup, but I quite like the
way this system (built by two collegues) turned out. It was our second
attempt at using pgsql for a bigger production site and while we ran
into a lot of problems, in the end it worked out very well :)
Regards,
Mathijs
--
It's not that perl programmers are idiots, it's that the language
rewards idiotic behavior in a way that no other language or tool has
ever done.
Erik Naggum
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2001-04-18 18:12 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-18 09:33 maybe Offtopic : PostgreSQL & PHP ? Picard, Cyril <cyril.picard@eads-dsn.com>
2001-04-18 12:35 ` Keith Wong <keith@e-magine.com.au>
2001-04-18 13:34 ` Roberto Mello <rmello@cc.usu.edu>
2001-04-18 14:54 ` Roberto Mello <rmello@cc.usu.edu>
2001-04-18 15:37 ` Josh Berkus <josh@agliodbs.com>
2001-04-18 18:12 ` Mathijs Brands <mathijs@ilse.nl>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox