473,326 Members | 2,114 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,326 software developers and data experts.

Persistent connections not limited to one Apache-process?

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 NNTP-connection
per session, and exactly one session per NNTP-connection).

Now, I'd like to have these connections be persistent. So I started
using "pfsockopen" instead of "fsockopen" and set Apache's
KeepAliveTimeout to a very high value. However, this doesn't work all
that great: Often browser-connections are closed prematurely and some
browsers have trouble with KeepAlive, anyway. After a
browser-connection has been closed, the next browser request will most
likely be answered by a different Apache process, and this process will
open a *different* persistent connection. In a nutshell:

* Persistency of the NNTP-connections over a lengthy period of time is
nearly impossible (unless the browser and the web server play well
together).

* More than one connection is created per session, which is a waste of
resources.

A solution that comes into my mind is using a separate daemon running on
the same machine as the web server. It would open persistent
NNTP-connections and connect them to a local socket. A PHP session
could then connect to that socket.

What do you recommend? Are there standard tools for that purpose? Any
ideas?

BTW, I'm running PHP4 on an Apache 2 LINUX-server, but upgrading
e.g. PHP should be no big problem.

--
Felix E. Klee

Jul 17 '05 #1
5 2774
Felix E. Klee <fe********@inka.de> wrote:
[snip]
What do you recommend? Are there standard tools for that purpose? Any
ideas?


Rule 1: don't optimize
Rule 2: don't optimize (yet)

Is there an actual problem with opening 1 tcp socket to the nntp server
per http request?

If there is you can:
-write a daemon like you suggested, can be written in any language you
feel comfortale with (that includes php).
-switch (partially) to an other enviroment which actually has support
for threading (eg Java/Servlets)

But that only fixes problems where setting up an initial connection to a
(nttp) server takes a huge amount of time (relatively speaking). But
that might also mean there is a network configuration error hidden
somewhere.

Jul 17 '05 #2
At 10 Jun 2005 00:58:04 GMT,
Daniel Tryba wrote:
Is there an actual problem with opening 1 tcp socket to the nntp
server per http request?
Yes, it takes several seconds since:

1. For authenticating a user, the news server needs to contact a
PostgreSQL database twice (once for verifying UID and password, and
once for deciding which groups the user has access to).

2. The server hosting the PostgreSQL database is quite slow.

Some alternatives to opening a persistent connection to the news server:

* Cache the login and groups data in a simple database that doesn't take
as long to connect to as PostgreSQL.

* Open a persistent connection to the PostgreSQL database for the perl
scripts doing the authentication.

Both of the above solutions appear about as complex as opening a
persistent connection to the news server. So I'm not too fond of them,
especially as they will be a bit slower.
If there is you can:
-write a daemon like you suggested, can be written in any language you
feel comfortale with (that includes php).
I'm unlikely the first person with such a problem, so I was hoping for a
pointer to a ready made solution.
-switch (partially) to an other enviroment which actually has support
for threading (eg Java/Servlets)


How could that help? However, concerning threading, it may be
interesting to try out how "pfsockopen" would behave with a
multithreaded Apache (see e.g. module MPM worker).

--
Felix E. Klee

Jul 17 '05 #3
At Fri, 10 Jun 2005 11:08:22 +0200,
Felix E. Klee wrote:
* Open a persistent connection to the PostgreSQL database for the perl
scripts doing the authentication.


Actually, this may be simpler than I thought it is: I discovered
SpeedyCGI and "DBI::connect_cached".

--
Felix E. Klee

Jul 17 '05 #4
Felix E. Klee <fe********@inka.de> wrote:
If there is you can:
-write a daemon like you suggested, can be written in any language you
feel comfortale with (that includes php).


I'm unlikely the first person with such a problem, so I was hoping for a
pointer to a ready made solution.


If that's true, you shouldn't have any trouble finding them :)
On the otherhand, it's quite simple to implement.
-switch (partially) to an other enviroment which actually has support
for threading (eg Java/Servlets)


How could that help?


Because in that environment you don't need to build an external daemon.
One could either create the daemon in an other thread, or in the case of
Java/Servlets one could just store the socket in the session (never
tried this but IMHO that simply should work).

Jul 17 '05 #5
At 10 Jun 2005 13:12:42 GMT,
Daniel Tryba wrote:
If there is you can:
-write a daemon like you suggested, can be written in any language you
feel comfortale with (that includes php).


I'm unlikely the first person with such a problem, so I was hoping for a
pointer to a ready made solution.


[...]
On the otherhand, it's quite simple to implement.


Hm, I'm afraid that it's not as simple as it looks at first sight: One
problem is that, although there is a one-to-one relationship between
sessions and connections, a user may run the same session in two
different browser windows which may cause two different PHP scripts to
access the same connection simultaneously.

--
Felix E. Klee

Jul 17 '05 #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...
4
by: M. Katz | last post by:
I'm relatively new to PHP/MySQL and I've heard about maintaining a persistent connection to the database. To save overhead, I'd like to maintain the connection in a session variable, but I have a...
2
by: Ivan | last post by:
Hi, I have a that page opens an imap connection; I need to refer to the connection across various pages. I don't want to reopen that connection on every page (vast waste of resources). I have...
2
by: Jim Hubbard | last post by:
Is it possible to have persistent connections in ASP.Net?
0
by: manji | last post by:
I had a problem with persistent connections and had to disable in on the webserver. Now i found out that the ASP.net debugger will not function if persistent connections are disabled. I hope...
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...
5
by: lawpoop | last post by:
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...
2
by: Scott Sharkey | last post by:
Hello All, I am trying to write a python script to talk to an xml-based stock feed service. They are telling me that I must connect and login, and then "issue refresh requests" to fetch the...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.