cgi scripts keeping connections open

We just moved to a new server and for some reason the cgi scripts are not closing the connection, and eventually there are no more connections available.

This didn’t happen on the old server but does on the new one.

How can I make sure the cgi connection is released?

My guess is that the new server has mod_cgi turned on and our cgi script is not configured for that.

So what should I have our server guy do?

Well, check and see if mod_cgi is on for your app and turn it off.

Hi Greg,

I work with Rich. I’m the server guy aforementioned above. We’re using cpanel with apache2. I’m a little confused by what you mean by turning off mod_cgi. What is the alternative?

We are using the following .htaccess to allow cgi execution outside of cgi-bin:

Options +ExecCGI order allow,deny deny from all <Files *.cgi> allow from all </Files>

Apache uses mod_cgi to load the cgi perl script and send the response to the browser. This works fine, but then the cgi script remains in memory taking up a connection slot. Once we hit our apache connection limit with stuck open children the site becomes no longer accessible.

Thoughts? Is there documentation on best practices for Xojo script deployment to cpanel?

Thanks,
Jeremy

[quote=380894:@Jeremy Driscoll]Hi Greg,

I work with Rich. I’m the server guy aforementioned above. We’re using cpanel with apache2. I’m a little confused by what you mean by turning off mod_cgi. What is the alternative?

We are using the following .htaccess to allow cgi execution outside of cgi-bin:

Options +ExecCGI order allow,deny deny from all <Files *.cgi> allow from all </Files>

Apache uses mod_cgi to load the cgi perl script and send the response to the browser. This works fine, but then the cgi script remains in memory taking up a connection slot. Once we hit our apache connection limit with stuck open children the site becomes no longer accessible.

Thoughts? Is there documentation on best practices for Xojo script deployment to cpanel?

Thanks,
Jeremy[/quote]
You’re right. There is another module though that causes cgi scripts to persist though. I’m trying to track that down now.

Aha! FastCGI. that’s what I was thinking of.

Hi Greg,

We are not using fastcgi. We were using mod_cgi. I tried switching us to mod_cgid (which is supposed to do less wrapping of the request and make the calls directly to perl) and that did not help. I also followed some advice on a cPanel forum and tried to use their 3rd party perl installation (/usr/local/cpanel/3rdparty/perl/524/bin/perl) instead of the system perl. This also had no effect.

Any ideas? We’ve gotten around the issue for the time being by killing all Xojo apps early in the morning, but this is not a long term solution.

Jeremy

Define what you mean by “connections”. CGI does not use connections the same way as standalone. It responds to arguments passed to it by the web server.

Thinking more on it… the perl script does start the Xojo app on a port socket. Have you done any checks to see if your session count is decreasing?

@Phillip Zedalis,

Thanks for chiming in. I’m referring to connections from a client browser to the website. Essentially:

Browser -> Apache -> Perl CGI app (Xojo)

The connections are left open even though the browser has received it’s data. I would expect that the cgi script would exit after it was completed. This does not appear to be the case. A sample of our process list looks like this:

/usr/sbin/httpd -k start
nobody    5878  0.0  0.1 192740  5464 ?        S    00:14   0:00  \\_ /usr/sbin/httpd -k start
nobody    6954  0.0  0.1  34684  4820 ?        S    00:36   0:00  |   \\_ /usr/bin/perl -w /home/user/public_html/xo/Registration/registration.cgi
nobody    7158  0.4  0.1  34688  4820 ?        S    00:37   0:00  |   \\_ /usr/bin/perl -w /home/user/public_html/xo/EndOfYear/endofyear.cgi
nobody    5880  0.0  0.3 2120104 14808 ?       Sl   00:14   0:00  \\_ /usr/sbin/httpd -k start

The perl processes remain open and as such keeps an apache connection slot open as well. Too many of these left over and we run out of available connections. It has gotten better switching from mod_cgi to mod_cgid. They do appear to drop off after awhile (usually), but I would expect the perl process to exit immediately after it has finished sending data to the browser and it does not.

To answer your other question, I’m not sure what you’re asking in terms of session count. Can you clarify? My understanding is that the Xojo perl script starts the Xojo app on a specific port and communicates with it, returning data to the browser through the script. The script should exit when it’s done and a new script from a new connection will check to see if the Xojo app is running, communicate with it if it is, and start it up if it isn’t. Perhaps my understanding of this is off since I’m not actually doing any Xojo development.

Tagging @Greg O’Lone and @Richard Albrecht as well.

Jeremy

So depending on how much traffic there is, each browser will have 1-4 connections running at any time. Each browser maintains an single open connection at all times so that if the server wants to send a message down, there’s a socket ready and waiting (it’s called long-polling).

Now on the other hand, by default a web app will only maintain up to 200 simultaneous connections, so at any given time that’s the maximum number of Perl scripts you should have running. It depends a lot on how many simultaneous users you have.

First thing I’d do is check how many actual sessions you have using App.SessionCount. Then take that number and the actual number of Perl processes and tell us what they are.

@Jeremy Driscoll @Greg O’Lone

I will build a little app to get you that count.

@Greg O’Lone

Hi I put an app that displays app.SessionCount, it only shows 1. How do I get it to show number of all sessions?

App.SessionCount is the number of sessions that are currently allocated. If you want the number that’s ever been created, you’ll have to add your own counter and add to it whenever Session.Open fires.

@Greg O’Lone

Does that mean Allocated in the current app or all session currently allocated by all the XoJo apps?

[quote=383026:@Richard Albrecht]@Greg O’Lone

Hi I put an app that displays app.SessionCount, it only shows 1. How do I get it to show number of all sessions?[/quote]

If you just created a separate app for this, then App.SessionCount will show only the Sessions associated with that app. To see how many Sessions are associated with the app of concern, however, you can place a button on that app that displays the SessionCount for that app when the button is pressed:

MsgBox App.SessionCount.ToText

[quote=383097:@Richard Albrecht]@Greg O’Lone

Does that mean Allocated in the current app or all session currently allocated by all the XoJo apps?[/quote]
In the current app. The apps do not communicate with one another.