Localized ht_time?

2000-10-19 Thread David E. Wheeler

Hi All,

Does anyone know if there is a way to get Apache::Util::ht_time() to
correctly format times based on the time zone in $ENV{TZ} the way that
POSIX::strftime() does? How 'bout getting it to use the correct language
the way POSIX::setlocale() makes POSIX::strftime() format in the correct
language?

TIA!

David

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: Localized ht_time?

2000-10-19 Thread David E. Wheeler

"David E. Wheeler" wrote:
 
 Hi All,
 
 Does anyone know if there is a way to get Apache::Util::ht_time() to
 correctly format times based on the time zone in $ENV{TZ}...

It does. Duh! Please ignore my spam.

David



Re: ht_time vs. strftime

2000-10-17 Thread David E. Wheeler

Matt Sergeant wrote:

 You should still switch to Time::Object. Loading POSIX.pm still loads in
 the .so which contains loads of cruft for things you don't
 want/need. Whereas loading Time::Object is a lot smaller. Of course I'm
 not sure how you'd fix the isdst thing with Time::Object, since it does
 strftime internally...

Perhaps you could add something like ht_time() has - it takes a third
argument indicating whether the time passed is UTC. If it is, it uses
gmtime internally, otherwise it uses localtime. And it looks like
ht_time()'s implementation of gmtime() properly returns the time zone
and doesn't add in DST stuff. Is that doable in Time::Object, or are you
using Perl's gmtime() there?

http://src.openresources.com/debian/src/web/HTML/S/ncsa_1.4.2.orig%20ncsa-1.4.2.orig%20src%20util.c.html#117

David

-- 
David E. Wheeler   Phone: (415) 645-9365
Software Engineer  Fax:   (415) 645-9204
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: ht_time vs. strftime

2000-10-17 Thread David E. Wheeler

Matt Sergeant wrote:
 
 Its doable - I could add in the code for ht_time almost verbatim, although
 I *am* using Perl's gmtime.

Could you not use the same gmtime that ht_time uses?

D

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



ht_time vs. strftime

2000-10-16 Thread David E. Wheeler

Hi All,

Can anyone tell me why these are not equivalent? Shouldn't strftime know
that the time returned from gmtime() is GMT? I'm trying to create a
library that'll use ht_time when $ENV{MOD_PERL} is true, ans strftime
otherwise. But they need to be consistent!

  use Apache::Util 'ht_time';
  my $t = ht_time;
  print "$t\n"; # prints "Mon, 16 Oct 2000 20:33:42 GMT"

  use POSIX 'strftime';
  my $a = strftime("%a, %d %b %Y %T %Z", gmtime);
  print "$a\n"; # prints  Mon, 16 Oct 2000 21:33:42 PDT

Thanks!

David

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: ht_time vs. strftime

2000-10-16 Thread David E. Wheeler

Matt Sergeant wrote:
 
 Sadly gmtime doesn't return any component indicating the timezone. Of
 course why not print out GMT instead of %Z?

Because it won't always be GMT.

 Alternatively, why not use Time::Object? It implements strftime without
 the overhead of POSIX.pm, and does it in XS too.

Does it know Time Zones? Here's what I've got so far. The idea is to get
$format_date to work correctly everywhere.

BEGIN {
if ($ENV{MOD_PERL}) {
use Apache::Util;
$format_date = \Apache::Util::ht_time;
} else {
use POSIX;
$format_date = sub {
POSIX::strftime($_[1] || "%a, %d %b %Y %T %Z", $_[0] ?
  localtime($_[0]) : gmtime);
};
}
}


Thanks,

David
-- 
David E. Wheeler   Phone: (415) 645-9365
Software Engineer  Fax:   (415) 645-9204
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: ht_time vs. strftime

2000-10-16 Thread David E. Wheeler

Matt Sergeant wrote:
 
 On Mon, 16 Oct 2000, David E. Wheeler wrote:
 
 I'm confused. Why are you using gmtime then?

Because if no time is supplied, I want it to default to GMT. I'm setting
up an app in which the database will store date/time in GMT only, but
will serve it out to users in their own local timezones. So sometimes
it'll be GMT and sometimes it won't.

  Does it know Time Zones?
 
 It just does strftime, so you can do what you've got below without loading
 POSIX. Plus its OO so it makes more sense (IMHO).

So %Z still won't work properly when I use gmtime.
 

 I'm not sure I understand the correctness of this. Shouldn't it be:
 
 gmtime($_[0] || time)
 
 or
 
 localtime($_[0] || time)
 

No, because if no time is supplied, I want UTC. If a time is supplied, I
want no alteration to that time (gmtime would correct it). The goal is
to get it to act exactly as ht_time does. Maybe this:

BEGIN {
if ($ENV{MOD_PERL}) {
use Apache::Util;
$format_date = \Apache::Util::ht_time;
} else {
use POSIX;
$format_date = sub {
POSIX::strftime($_[1] || $_[0] ? "%a, %d %b %Y %T %Z" :
"%a, %d %b %Y %T GMT", $_[0] ? localtime($_[0]) :
(gmtime)[0..7]);
};
}
}

Which also corrects for the one hour difference between them (why would
gmtime() ever return true for daylight savings??? It does!

D

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: Wild Proposal :)

2000-10-12 Thread David E. Wheeler

Perrin Harkins wrote:
 
 My point was that Apache::DBI already gives you persistent connections,
 and when people say they want actual pooled connections instead they
 usually don't have a good reason for it.

Let's say that I have 20 customers, each of whom has a database schema
for their data. I have one Apache web server serving all of those
customers. Say that Apache has forked off 20 children. Each of the
customers who connects has to use their own authentication to their own
schema. That means that Apache::DBI is caching 20 different connections
- one per customer. Not only that, but Apache::DBI is caching 20
different connections in each of the 20 processes. Suddenly you've got
400 connections to your database at once! And only 20 can actually be in
use at any one time (one for each Apache childe).

Start adding new customers and new database schemas, and you'll soon
find yourself with more connections than you can handle.

And that's why connection pooling makes sense in some cases.

David

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Forking in mod_perl?

2000-10-04 Thread David E. Wheeler

Hi All,

Quick question - can I fork off a process in mod_perl? I've got a piece
of code that needs to do a lot of processing that's unrelated to what
shows up in the browser. So I'd like to be able to fork the processing
off and return data to the browser, letting the forked process handle
the extra processing at its leisure. Is this doable? Is forking a good
idea in a mod_perl environment? Might there be another way to do it?

TIA for the help!

David

-- 
David E. Wheeler
Software Engineer
Salon Internet ICQ:   15726394
[EMAIL PROTECTED]   AIM:   dwTheory



Re: Forking in mod_perl?

2000-10-04 Thread David E. Wheeler

ed phillips wrote:
 
 Hi David,
 
 Check out the guide at
 
 http://perl.apache.org/guide/performance.html#Forking_and_Executing_Subprocess
 
 The Eagle book also covers the C API subprocess details on page 622-631.
 
 Let us know if the guide is unclear to you, so we can improve it.

Yeah, it's a bit unclear. If I understand correctly, it's suggesting
that I do a system() call and have the perl script called detach itself
from Apache, yes? I'm not too sure I like this approach. I was hoping
for something a little more integrated. And how much overhead are we
talking about getting taken up by this approach?

Using the cleanup phase, as Geoffey Young suggests, might be a bit
nicer, but I'll have to look into how much time my processing will
likely take, hogging up an apache fork while it finishes.

Either way, I'll have to think about various ways to handle this stuff,
since I'm writing it into a regular Perl module that will then be called
from mod_perl...

Thanks,

David



Re: Forking in mod_perl?

2000-10-04 Thread David E. Wheeler

ed phillips wrote:
 
 I hope it is clear that you don't want fork the whole server!
 
 Mod_cgi goes to great pains to effectively fork a subprocess, and
 was the major impetus I believe for the development of
 the C subprocess API. It  (the source code for
 mod_cgi) is a great place to learn some of the
 subtleties as the Eagle book points out. As the Eagle book
 says, Apache is a complex beast. Mod_perl gives
 you the power to use the beast to your best advantage.

Yeah, but I don't speak C. Just Perl. And it looks like the way to do it
in Perl is to call system() and then detach the called script. I was
trying to keep this all nice and tidy in modules, but I don't know if
it'll be possible.

 Now you are faced with a trade off.  Is it more expensive to
 detach a subprocess, or use the child cleanup phase to do
 some extra processing? I'd have to know more specifics to answer
 that with any modicum of confidence.

I think I can probably evaluate that with a few tests.

Thanks!

David



Re: Forking in mod_perl?

2000-10-04 Thread David E. Wheeler

Billy Donahue wrote:

  Now you are faced with a trade off.  Is it more expensive to
  detach a subprocess, or use the child cleanup phase to do
  some extra processing? I'd have to know more specifics to answer
  that with any modicum of confidence.
 
 He might try a daemon coprocesses using some IPC to communicate with
 Apache, which is my favorite way to do it..

Yeah, I was thinking something along these lines. Don't know if I need
something as complex as IPC. I was thinking of perhaps a second Apache
server set up just to handle long-term processing. Then the first server
could send a request to the second with the commands it needs to execute
in a header. The second server processes those commands independantly of
the first server, which then returns data to the browser.

But maybe that's overkill. I'll have to weigh the heft of the
post-request processing I need to do.

Thanks for the suggestion!

David



Re: Dissappearing Lexicals

2000-08-31 Thread David E. Wheeler

Matt Sergeant wrote:
 
 On Wed, 30 Aug 2000, mgraham wrote:
 [snip]
  Personally, I've given up on package-scoped lexicals entirely, and
  moved everything into "use vars".  It's a pain, because you lose the
  encapsulation and you have to declare and assign the variables
  separately.  But it generally seems much more robust and predictable.
 
 This is a real worry for anyone using the Tie::SecureHash sort of thing to
 hide access to private variables.

Okay, I'll try to whip up a quick example today of this issue and submit
it to the list. It seems worthwhile to me to try to get this bug(?)
squashed for the reason Matt brings up and others.

David



Dissappearing Lexicals

2000-08-29 Thread David E. Wheeler

Hi All,

I've encounted a strange problem with our mod_perl installation. I have
a library for handling DBI stuff, and store the $dbh in a package-level
lexical. The $dbh is not populated until the first time a DBI call is
made - which is during a request and therefore always after Apache
forks. The $dbh is then used by various functions exported into other
modules.

However, in some of these functions, $dbh seems to be out of scope! In
other words, In some functions, the $dbh works fine, while in others, it
says "cannot call method 'selectcol_arrayref' on an undefined value."
Sure enough, it thinks that $dbh is undefined, even though it will show
up defined in other functions called just prior to or after the function
that attempts to call selectcol_arrayref. I have not my'd it within the
scope of the function - it is only declared at the package-level.

Now, I've managed to solve the problem by simply making $dbh a package
variable (use vars '$dbh';). However, the package-level lexical *was*
working on Friday, but would not as of yesterday!

Anyone got any ideas what the heck is happening to the value stored in
$dbh? I can provide more details about the construction of my DBI
library if you think that will help diagnose the problem.

Details: All DBI calls are made in one request, so there's no chance of
some calls being in different forks where $dbh may not yet have been
defined. Also, the DBI library I've written works fine when run from the
shell - it's only in mod_perl that it fails.

The setup: Solaris 2.4 running Apache 1.3.12  mod_perl 1.24. DBI is
version 1.14 and DBD::Oracle version 1.06.

TIA!

David



Can't Locate Apache::File

2000-08-29 Thread David E. Wheeler

Hi All,

I've just installed the latest version of Lincoln Stein's Apache::MP3
(nice job, Doc!), which offers support for caching MP3 ICY info. It uses
Apache::File to do so. This the first time I've used Apache::File on
this server, but was still surprised to find that it failed to load:

[Wed Aug 23 10:14:53 2000] [error] Can't locate loadable object for
module Apache::File in @INC (@INC contains:
/usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005
. /usr/local/apache/ /usr/local/apache/lib/perl) at
/usr/lib/perl5/site_perl/5.005/i386-linux/mod_perl.pm line 65535

As near as I can tell, it is in fact there, and when I do

% perl -le 'use Apache::File;'

It seems to load just fine. The module lives in
/usr/lib/perl5/site_perl/5.005/i386-linux/Apache/File.pm Anyone got any
idea why it can't find it?

I'm running Apache 1.3.12 with mod_perl 1.24 compiled in on RedHat Linux
6.2.

TIA!

David