473,233 Members | 1,420 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,233 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 2768
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
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...

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.