RE: Cheap and unique
David Jacobs wrote: > > I'm converting a few CGI scripts that used the PID as a cyclical unique > number (in concert with TIMESTAMP - so it was TIMESTAMP.PID). > > Our goal is to find a replacement function that is extremely cheap > (cheaper than say, random(100)) and will never repeat. Any ideas? > Has anyone else faced this problem? I use $$.$r->uri().$connections.time where $connections is an incremental value defined before sub handler {...} and do $connections++ w/in the handler block (also realizing that you're porting CGI's and will have to get the uri elsewhere). For example: package foo; my $connections = 0; sub handler { my $r = shift ; ... ... ... my $unique_id = $$ . $r->uri() . $connections . time ; ... ... ... $connections++ ; } 1; Regards, Dave http://www.linkreminder.com
Apache::Sybase::CTlib connections dropping (not morning issue)
Hi all, I have an unstable connection to my backend database (I have no control). The connection often blinks which causes the Apache children processes to drop. I am trying to figure out a way to automatically reconnect. I am currently writing a script to run outside of Apache which will make a connection. When the connection blinks, the script will gracefully restart the server. There has to be a way to do this within the mod_perl environment - Any ideas? Thanks in advance for any help ... Dave Homsher, Webmaster MACtac IT -- It's always darkest just before it goes pitch black.
zlib error?
Hi all, I came in this morning to find my server (semi) down with the following error message in the logs: [error] Out of memory during "large" request for 135168 bytes at /opt/perl5/lib/site_perl/5.6.0/PA-RISC2.0/Compress/Zlib.pm line 198 This is on an HP-UX machine with several _gigs_ of memory. In my mod_perl modules, I compress my cookies (using Compress::Zlib) before sending them across to the browser. All of the mods that generate cookies were getting an internal server error :/ I did apachectl graceful with no luck, then apachectl restart with no luck again, and finally a stop and start fixed the problem, but for how long? Has anyone seen this or know where to start looking? It appears to be some sort of memory leak, but where to begin looking? Thanks, Dave Homsher, II Webmaster MACtac IT
STDOUT issues ...
Hi all ... I have searched through the archives for an answer and have found a lot of discussion, but nothing concrete enough to help ... I am using Spreadsheet::WriteExcel to create an Excel doc (hence the name) but I keep getting blank documents back. The module can write to a file or to STDOUT using '-'. From the archives I see that this is similar to an issue with Apache::Magick where the C STDOUT (expressed as '-' or '>-') is different from Perl's default STDOUT. I have also tried the code from the mod_perl guide: use constant IS_MODPERL => $ENV{MOD_PERL}; if (IS_MODPERL) { tie *OUT, 'Apache'; } else { open (OUT, ">-"); } I'm probably not using this as intended, though (an example would help). Does this go before the handler sub, or in it ??? Here is the code below (BTW it does work as a plain cgi script w/o the mod_perl additions of course). You can see the different ways I have been trying to do this ... package Planning_xls; # File: /usr/local/apache/lib/perl/Planning_xls.pm use strict; use Apache::Constants qw(:common REDIRECT HTTP_SERVICE_UNAVAILABLE); use Spreadsheet::WriteExcel; sub handler { my $r = shift; use constant IS_MODPERL => $ENV{MOD_PERL}; if (IS_MODPERL) { tie *OUT, 'Apache'; } else { open (OUT, ">-"); } # *STDOUT = *r{IO}; # tie *STDOUT => Apache; # tie *STDOUT => $r; # tie *STDOUT => 'Apache'; # open(STDOUT, ">-"); # untie *STDOUT; # open(STDOUT, ">&=" . fileno($fh)); $r->content_type('application/vnd.ms-excel'); # $r->content_type('text/html'); $r->send_http_header; my $workbook = Spreadsheet::WriteExcel->new("-"); # my $workbook = Spreadsheet::WriteExcel->new(STDOUT); my $worksheet = $workbook->addworksheet("test"); my $format = $workbook->addformat(); $format->set_bold(); $format->set_color('red'); $format->set_align('center'); $worksheet->write(0, 0, 1); $worksheet->write(1, 1, 1.2345); $worksheet->write(2, 2, "formatted", $format); $workbook->close(); return OK; } 1; __END__ Thanks for any help ... I know I am missing something obvious ... Dave Homsher Webmaster MACtac IT "The tree of liberty must be watered periodically with the blood of tyrants and patriots alike. ... Resistance to tyrants is obedience to God." - Thomas Jefferson
Advocacy idea ...
Hi all, With all of the advocacy talk on the ML right now I've been mulling around the idea of having a "peer review" forum where one could post code that you are currently working on w/an explanation of what you are trying to accomplish and have the community review/give suggestions warnings, etc. or how to improve code (maybe /. style?). I know from my experience that having others review your code is always helpful (well almost always :) ). In my work situation right now I am the only person that knows anything about mod_perl and we really only have one other person who knows any Perl at all (and this was v. 4). So I know that some stupid things are slipping through ... I have been hesitant to suggest anything on the list as I've only been on it for 2 months or so, but if this would be beneficial, I would be willing to help as time permits ... I don't think that there is anything like this around (for Perl or Java), although I could be wrong ... Does the idea have merit? If so, how to proceed? Dave Homsher Webmaster, MACtac IT "The tree of liberty must be watered periodically with the blood of tyrants and patriots alike. ... Resistance to tyrants is obedience to God." - Thomas Jefferson
RE: [OT]: Open Source ... was Re: Advocacy idea ...
>>Just don't post your code to the list itself. It's rude to >>bloat the mails on the list. Provide a hyperlink to your annotated code. True, but what happens after you get your answer? You take the code down and move on. It would be nice to have a place to post the code where it can be organized and filed away with comments for future reference. Also the idea would be more "code review" than "I have a problem". From my perspective, I would like to see how others are solving problems and how successful they were through a given solution. Maybe even have a moderating system so that good code/comments float to the top ??? There are all kinds of bits and pieces of floating around the net and in print: CPAN, O'Reilly books, Mailing list, etc. I can read perldocs to see how a module is used, I can check out O'Reilly books for theory and simple examples, and I can ask a mailing list for help when I get stuck, but sometimes you don't know what module will help, you've read the O'Reilly books and the examples are too simple/don't apply, and you aren't even sure what question to ask the mailing list, what do you do? I bludgeon together some code and hope that is good enough. I don't really have anyone to review it and say "This is stupid". I realize that you will probably have people do the cut and paste thing, but if it's good code, is that really a problem - especially if there are comments, etc. and an explanation of how the code works/is supposed to work from the author??? I see this as both a code resource and a review forum ... Thoughts??? Dave Homsher Webmaster, MACtac IT
RE: [OT]: Open Source ... was Re: Advocacy idea ...
>>OK, you probably don't want it to be another mailing list >>then. But a web >>bbs that allows you to post replies to code. kind of ... I would like to see someplace to post _working_ code (complete or snippets) with an explanation of what you are trying to accomplish, and with any issues/special circumstances that you had to take into account. You would post to one of several categories (Database, XML, OOP, etc.). Maybe have the functionality for reviewers to alter the code and have the site produce a diff automagically from the changes. You could maybe see the code with changes that were made by a select number of people (maybe people who have highly moderated suggestions/code?). Possibly have in each section for links to resources that can be moderated for usefulness in each of these categories (this may already exist -- if it does, please let me know where! :)) >>Yet such code reviews are >>extremely time >>consuming so I could see people donating time once a month to >>do it but not >>much more realistically (based on the fickle *real* workload >>we all have). This is very true, and I also think there would be the whole "critical mass" issue (people won't use it until it's big / it won't be big until people use it). I think there would certainly need to be clear guidelines as well (TBD) >>Anyway, however you want to go about it, good luck. I think that I will try to come up with a proposal over the weekend (or at least by the end of the week - Saturday is my b-day :)). Perhaps at that time a consensus of whether this is worthwhile could be achieved? >>Usually people go to the archive when they have a problem not >>pre-emptively. And I think that although the code someone has >>posted for >>comments on the main mailing list may no longer be there, the >>comments >>about that code remain and usually with snippets of the code >>in question. {snip} >>I don't think this list lacks for discussion on code that >>people might post >>(although lately its this advocacy stuff). So although it is >>better to have >>a separate code repository, I am not sure that people would >>flock to it >>enough to make it better than posting the code to the list >>(as a URL) and >>discussing it here. This could even go beyond coding (I am brainstorming here ... unencumbered by the thought process). Perhaps create an area for project plans, hardware setup, etc. (of course relating to mod_perl). I find that my biggest issue is usually not coding problems per se, but "what is the best way to go about doing this?" or "did I miss something in the code that I will regret later?". These are my biggest itches. As I mentioned previously, I have no one to bounce things off of. I am in Ohio which is the land of MS/ASP/VB. I have been able to convince my employers that mod_Perl is good technology (mostly based upon speed). I don't want to prove the decision wrong by some silly mistake (I've been OK so far). Most of the resources that I can find on the net have to do with "I can't get this to work" and not "Is this good?". I realize that most of this knowledge comes with experience, but this could be a place to bounce ideas around and perhaps jumpstart that experience. Your earlier comment about this being what open source is all about may be very accurate here. Am I describing SourceForge? CPAN? ML's? something else? Also please let me know if this is trailing too far off topic. Is there a more appropriate place to discuss this? Best Regards, Dave Homsher Webmaster, MACtac IT
RE: Not embedding SQL in perl
Joe Breeden queried: >>It would be interesting to know how other people have solved >>that problem. >>Currently, we are essentially using embedded SQL in our apps. I have found that stored procedures + perl module wrapper around the procs. is a nice, balanced approach. The procs. give a nice performance boost as they are precompiled into the server (we use Sybase). I believe that they are more secure, in that you aren't dynamically generating sql that might be 'hijack-able'. You are providing a discrete amount of functionality. Placing the stored procedure execution code in a perl module makes for easy/clean perl access from the rest of the app. Moving to a new db isn't too terribly difficult in that the proc names will probably remain as well as the parameters that you pass. Also, how often do you move to another database in the life of a web app anyway (at least in our corporate environment)? Regards, Dave "Language shapes the way we think, and determines what we can think about." -- B. L. Whorf
Apache 2.0 / mod_perl 2.0 / Win NT/2000 ? pipe dream ?
Hi all, We currently use (close to) the latest Apache / mod_perl environment on HP/UX. Our holding company is forcing a move to Win2k :/, but they still want to use our mod_perl apps :). I was looking for more information on mod_perl 2.0 today but didn't come up w/much. I have several questions. If you can answer or point to docs, I would be most appreciative. 1) Is moving to mod_perl 2.0 going to require large code changes (even on a *nix system)? 1a) Are there any web sites detailing the types of changes that will be required? 2) I am aware that Apache 2.0 should see a performance increase on NT. Will I be a able to run my current modules in this environment? 2a)Will it be a "production level" environment? 2b) What will be the performance repercussions (if it will be possible at all)? 3) Is there any commercial company that would provide tech support contracts in this environment (not that I've needed it so far, but the uppers like the safety net)? 4) Is the code base stable enough that I can compile and test this out (I really can't even find a site that deals w/ mod_perl 2 in any detail - probably looking in the wrong places - I would think that perl.apache.org would mention something? - am I blind? ) Thanks for any assistance you can provide. Best Regards, Dave Webmaster MACtac IT "Language shapes the way we think, and determines what we can think about." -- B. L. Whorf
Re: Not embedding SQL in perl
>> >>It would be interesting to know how other people have solved >> >>that problem. >> >>Currently, we are essentially using embedded SQL in our apps. >> >> I have found that stored procedures + perl module wrapper >>around the >>procs. >> is a nice, balanced approach. >> >Definitely; stored procedures are hit-and-miss in a lot of >environments. >Remember that a large number of people in the mod_perl world >can't use 'em >because they (we) use MySQL. If one wanted to emulate this >behavior with >MySQL, you would essentially clone the functionality of your stored >procedures using Perl + DBI inside your persistence layer. That is a >perfectly viable approach too, but a lot less efficient than stored >procedures (many roundtrips versus one). Interesting, I will be working w/MySQL in a few days on a side project of my own. We'll see how my outlook changes ;) Any recommendations? Regards, Dave "Language shapes the way we think, and determines what we can think about." -- B. L. Whorf
Re: compiling troubles on Solaris 8
>> As an aside, Solaris 8 comes with prebuilt versions of Apache >> and mod_perl, >does anyone familiar with HP-UX, AIX, or IRIX know whether this is true of >these platforms as well? >Whether they are DSO mod_perl or not would also be helpful. HP-UX doesn't consider Perl a supportable piece of software, nor Apache. Needless to say, it doesn't come prebuilt. The compiler that comes w/the os isn't ansii compliant and is only good for rebuilding the kernel (but hey, you can buy HP's ansii c compiler for only a few thousand dollars!). We ended up building a gnu development environment in order to build mod_Perl. We could not get it to work as a DSO :(. Once we got everything up and running, it's a decent enough platform. Regards, Dave Homsher