You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tommy Davis <mo...@adapt.dk> on 2001/05/02 10:01:53 UTC
Syntax errors across multiple virtual hosts with separate codebase
We use a server-setup with a mod_perl enabled backend server. The server
only runs mod_perl and mySQL for about 5 virtual hosts.
Our problem is that a syntax-error in a program used on only one virutal
host, causes an "internal server error" across all virtual hosts.
I suspect it's not possible to avoid this, but I would like to be sure.
Can anyone confirm this?
Another problem is that the solutions uses diffferent databases. That
means we end up with 5 ttimes as many open db handles as we have
mod_perl processes.
We have worked around this by merging all databases into a single one,
prefixing the table_names with the former db-names and using a simple
abstraction layer to access the database.
I would be very interested to hear how others have solved this problem (
without buying more servers ;-).
--
Med venlig hilsen
-Toem
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by Tommy Davis <mo...@adapt.dk>.
Chris Winters wrote:
>* Tommy Davis (mod-perl@adapt.dk) [010502 04:11]:
>
>>We use a server-setup with a mod_perl enabled backend server. The server
>>only runs mod_perl and mySQL for about 5 virtual hosts.
>>
>>...
>>
>>Another problem is that the solutions uses diffferent databases. That
>>means we end up with 5 ttimes as many open db handles as we have
>>mod_perl processes.
>>We have worked around this by merging all databases into a single one,
>>prefixing the table_names with the former db-names and using a simple
>>abstraction layer to access the database.
>>
>
>I'm not sure how you create your database handles (in a central
>location then passed around, or in each handler as you need it), but
>in MySQL (as with other databases) you can execute a 'use <dbname>' to
>start using a different database.
>
>So your definition can be the same for all virtual hosts but you can
>define a variable via PerlSetVar or in a configuration file that has
>the database name. When you ask for a database handle you can then
>create it using a common database name (e.g, 'mysql') and then
>execute the 'use <dbname>' statement:
>
Thanks a bunch - I never thought about using "use <dbname>" in a
mod_perl/DBI context. It's obvious when you know it ;-).
--
Med venlig hilsen
-Toem
Tommy Davis, Technical Director
Adapt A/S, Havnegade 41, 2. sal, 1058 K�benhavn K
Tel +45 3341 1050, Fax +45 3341 1069, http://www.adapt.dk/
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by darren chamberlain <dl...@users.sourceforge.net>.
Chris Winters (chris@cwinters.com) said something to this effect on 05/02/2001:
> package MyServer::DB;
>
> use strict;
> use DBI;
>
> my $DB_USER = 'xxxx';
> my $DB_PASS = 'yyyy';
>
> sub connect {
> my ( $class, $dbname ) = @_;
> my $dbh = DBI->connect( 'DBI:mysql:mysql', $DB_USER, $DB_PASS,
> { RaiseError => 1 } )
> || die "$DBI::errstr\n";
> $dbh->do( "use $dbname" ) if ( $dbname );
> return $dbh;
> }
I wrote something like this once:
#######################################################################
package MyDB;
use DBI;
use base 'DBI::db';
{
my $dsn;
sub import {
my $class = shift;
while (@_) {
my ($n, $v) = splice @_, 0, 2;
$dsn->{$n} = $v;
}
}
sub new {
my $class = shift;
my $dbh = DBI->connect(
sprintf('dbi:mysql:%s:%s', @{$dsn}{'database','hostname'}),
$dsn->{'username'}, $dsn->{'password'},
{ RaiseError => 1 });
bless $dbh, $class;
}
}
sub DESTROY { shift->disconnect }
1;
#######################################################################
(With a little sanity checking inside &import to make sure all
the required entries at least have reasonable defaults).
Which gets used like so:
#!/usr/bin/perl
use MyDB username => 'foo', password => 'bar';
my $db = MyDB->new;
It makes all the database stuff a little cleaner, and a little
better encapsulated.
(darren)
--
Pessimests are right more often, but optimists are happy more often.
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by Pete Jordan <mo...@horus.org.uk>.
Chris Winters <ch...@cwinters.com> wrote:
> I'm not sure how you create your database handles (in a central
> location then passed around, or in each handler as you need it), but
> in MySQL (as with other databases) you can execute a 'use <dbname>' to
> start using a different database.
FWIW, MySQL is quite happy performing queries on foreign databases through
DBI; I've needed to do this to perform queries that span tables on
multiple databases. Not sure of the performance overhead, but if you fully
qualify your fields (as in db.table.field) it shouldn't matter what
database your handle is actually opened on.
Pete
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by Chris Winters <ch...@cwinters.com>.
* Tommy Davis (mod-perl@adapt.dk) [010502 04:11]:
> We use a server-setup with a mod_perl enabled backend server. The server
> only runs mod_perl and mySQL for about 5 virtual hosts.
>
> ...
>
> Another problem is that the solutions uses diffferent databases. That
> means we end up with 5 ttimes as many open db handles as we have
> mod_perl processes.
> We have worked around this by merging all databases into a single one,
> prefixing the table_names with the former db-names and using a simple
> abstraction layer to access the database.
I'm not sure how you create your database handles (in a central
location then passed around, or in each handler as you need it), but
in MySQL (as with other databases) you can execute a 'use <dbname>' to
start using a different database.
So your definition can be the same for all virtual hosts but you can
define a variable via PerlSetVar or in a configuration file that has
the database name. When you ask for a database handle you can then
create it using a common database name (e.g, 'mysql') and then
execute the 'use <dbname>' statement:
package MyServer::DB;
use strict;
use DBI;
my $DB_USER = 'xxxx';
my $DB_PASS = 'yyyy';
sub connect {
my ( $class, $dbname ) = @_;
my $dbh = DBI->connect( 'DBI:mysql:mysql', $DB_USER, $DB_PASS,
{ RaiseError => 1 } )
|| die "$DBI::errstr\n";
$dbh->do( "use $dbname" ) if ( $dbname );
return $dbh;
}
We do something like this in OpenInteract and, for MySQL at least, it
works fine.
Chris
--
Chris Winters (chris@cwinters.com)
Building enterprise-capable snack solutions since 1988.
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by Tommy Davis <mo...@adapt.dk>.
G.W. Haywood wrote:
>>We use a server-setup with a mod_perl enabled backend server. The server
>>only runs mod_perl and mySQL for about 5 virtual hosts.
>>
>>Our problem is that a syntax-error in a program used on only one virutal
>>host, causes an "internal server error" across all virtual hosts.
>>I suspect it's not possible to avoid this, but I would like to be sure.
>>Can anyone confirm this?
>>
>
>Nope. I suspect your code isn't as separate as you think it is.
>
I'm quite sure the they are separate, but I'll try some simple
test-scenarios tonight to double-check.
--
Med venlig hilsen
-Toem
Tommy Davis, Technical Director
Adapt A/S, Havnegade 41, 2. sal, 1058 K�benhavn K
Tel +45 3341 1050, Fax +45 3341 1069, http://www.adapt.dk/
Re: Syntax errors across multiple virtual hosts with separate codebase
Posted by "G.W. Haywood" <ge...@www.jubileegroup.co.uk>.
Hi there,
On Wed, 2 May 2001, Tommy Davis wrote:
> We use a server-setup with a mod_perl enabled backend server. The server
> only runs mod_perl and mySQL for about 5 virtual hosts.
>
> Our problem is that a syntax-error in a program used on only one virutal
> host, causes an "internal server error" across all virtual hosts.
> I suspect it's not possible to avoid this, but I would like to be sure.
> Can anyone confirm this?
Nope. I suspect your code isn't as separate as you think it is.
73,
Ged.