You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by vi...@thepenguin.org on 2013/08/21 21:59:34 UTC

Testing session persistence with a php script

I am trying to figure out if I can run my sessionpersistence script that I run with Apache to see if sessions persist between two tomcat sites on two separate servers. The load balancer has session persistence enabled but Iam unsure how to test it. My thought was that I would just add the following php script to check, but apparently I am doing something wrong. The script is this:

 
<?php
// DONT FORGET TO CHECK FOR VARNISH RUINING EVERYTHING
ini_set( 'display_errors', 1);
session_start();

echo 'HOSTNAME: ' . gethostname() . '<br />';
echo 'SESSION: ' . session_id() . '<br />';

if (isset($_SESSION['counter'])) {
$_SESSION['counter']++;
} else {
$_SESSION['counter'] = 1;
}

echo '<br />DUMP SESSION:<br />';
echo '<pre>';
print_r($_SESSION);
echo '</pre>';

phpinfo();
?>

but it seems not to like it if I add it from the webapps directory or from inside a directory under that. Is there some special trick to running php from inside tomcat ? I have tomcat set up the same on both servers and am fronting it with Apache if that adds options for me.

Thanks for any ideas,
CaptainVic


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Testing session persistence with a php script

Posted by Mark Eggers <it...@yahoo.com>.
On 8/21/2013 12:59 PM, vicki@thepenguin.org wrote:
> I am trying to figure out if I can run my sessionpersistence script
> that I run with Apache to see if sessions persist between two tomcat
> sites on two separate servers. The load balancer has session
> persistence enabled but Iam unsure how to test it. My thought was
> that I would just add the following php script to check, but
> apparently I am doing something wrong. The script is this:
>
>
> <?php // DONT FORGET TO CHECK FOR VARNISH RUINING EVERYTHING ini_set(
> 'display_errors', 1); session_start();
>
> echo 'HOSTNAME: ' . gethostname() . '<br />'; echo 'SESSION: ' .
> session_id() . '<br />';
>
> if (isset($_SESSION['counter'])) { $_SESSION['counter']++; } else {
> $_SESSION['counter'] = 1; }
>
> echo '<br />DUMP SESSION:<br />'; echo '<pre>'; print_r($_SESSION);
> echo '</pre>';
>
> phpinfo(); ?>
>
> but it seems not to like it if I add it from the webapps directory or
> from inside a directory under that. Is there some special trick to
> running php from inside tomcat ? I have tomcat set up the same on
> both servers and am fronting it with Apache if that adds options for
> me.
>
> Thanks for any ideas, CaptainVic

You really don't want to run PHP from inside of Tomcat. It can be done, 
and probably the cleanest way to do it is to add the executable 
init-param to the cgi servlet and point it to php.

1. copy the cgi servlet definition out of web.xml and add it to your
    web.xml
2. add the init-param for PHP
3. make sure to mark your context as privileged

This will make your application Tomcat-specific. You could edit the 
distributed web.xml in $CATALINA_BASE/conf, but then that Tomcat could 
only run PHP (and not the default perl).

. . . . just my two cents.
/mde/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Testing session persistence with a php script

Posted by Daniel Mikusa <dm...@gopivotal.com>.
On Aug 21, 2013, at 3:59 PM, vicki@thepenguin.org wrote:

> I am trying to figure out if I can run my sessionpersistence script that I run with Apache to see if sessions persist between two tomcat sites on two separate servers. The load balancer has session persistence enabled but Iam unsure how to test it. My thought was that I would just add the following php script to check, but apparently I am doing something wrong. The script is this:
> 
> 
> <?php
> // DONT FORGET TO CHECK FOR VARNISH RUINING EVERYTHING
> ini_set( 'display_errors', 1);
> session_start();
> 
> echo 'HOSTNAME: ' . gethostname() . '<br />';
> echo 'SESSION: ' . session_id() . '<br />';
> 
> if (isset($_SESSION['counter'])) {
> $_SESSION['counter']++;
> } else {
> $_SESSION['counter'] = 1;
> }
> 
> echo '<br />DUMP SESSION:<br />';
> echo '<pre>';
> print_r($_SESSION);
> echo '</pre>';
> 
> phpinfo();
> ?>
> 
> but it seems not to like it if I add it from the webapps directory or from inside a directory under that. Is there some special trick to running php from inside tomcat ?

Tomcat is meant to run Servlet based Java apps, not PHP.  Use Apache HTTPD to run PHP.

> I have tomcat set up the same on both servers and am fronting it with Apache if that adds options for me.

Just use the manager application that is bundled with Tomcat to check sessions.

   https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html

Dan

> 
> Thanks for any ideas,
> CaptainVic
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org