Comment Spam & LiteratureI finally got fed up with manually monitoring the spam messages, but I didn't want to turn off anonymous comments. I figured captcha was the answer, but what was the easiest way? photo.net, the awesome photographry site built and run by Philip Greenspun is built on a similar platform to this site, and I knew it had captcha. Philip is true to his word on the importance of open source software, and the api and code of his site is publicly available. I discovered that photo.net uses a free service called reCAPTCHA - and it's brilliant! It gives you two words to type in. One that it knows the answer to (to check you're a human) and the other is a curly word that the OCR system at Carnegie Mellon University couldn't figure out while scanning books for the public good. I assume they run the unknown word through a number of captcha queries and pick the most popular interpretation. Now that's really crowd-sourcing! 09:52 PM, 26 Jul 2008 by Mark Aufflick Permalink | Comments (1) TWiki on FastCGII couldn't find much discussion of TWiki on FCGI. There is a beta project to make a standalone TWiki daemon which can also be run under FCGI, but I had already installed TWiki 4.2.0 so I was reticent to reinstall from a different branch. I only really needed to speed up the view cgi, so it shouldn't be too hard surely? I already had mod_fcgid installed on my Apache2 server. It turned out to really be very easy, and seems to be working fine so far. Here is my diff for twiki/bin/view: --- view~ 2008-01-22 14:18:52.000000000 +1100
+++ view 2008-07-20 18:40:33.000000000 +1000
@@ -27,6 +27,14 @@
require 'setlib.cfg';
}
+use FCGI;
use TWiki::UI;
use TWiki::UI::View;
-TWiki::UI::run( \&TWiki::UI::View::view, view => 1 );
+
+my $request = FCGI::Request;
+while ($request->Accept >= 0) {
+ eval {TWiki::UI::run( \&TWiki::UI::View::view, view => 1 );};
+ warn $@ if $@;
+ $request->Flush;
+ $request->Finish;
+}
And I added the following to the bin <Directory> section in my apache config: <FilesMatch "^view$"> SetHandler fcgid-script </FilesMatch> This seemed to work fine, but searches failed to spawn grep correctly. I think diffs would have also failed to spawn rcs. So I switched over to the pure perl versions by making the following settings in LocalSite.cfg: $TWiki::cfg{StoreImpl} = 'RcsLite';
TWiki::cfg{RCS}{SearchAlgorithm} = 'TWiki::Store::SearchAlgorithms::PurePerl';
Working a treat so far - Memory use seems ok. It rose from about 14000k up to about 15200k, and then hovered around that level indefinately. I'll let you know if I see any memory leaks or wierd issues. Update: I guess the pure perl search implementation isn't well used. It threw up a taint error when I tried to use it. No matter, the fix was as simple as replacing a horrible piece of string eval: --- lib/TWiki/Store/SearchAlgorithms/PurePerl.pm~ 2008-01-22 14:18:55.000000000 +1100
+++ lib/TWiki/Store/SearchAlgorithms/PurePerl.pm 2008-07-20 19:32:58.000000000 +1000
@@ -46,9 +46,14 @@
# Convert GNU grep \< \> syntax to \b
$searchString =~ s/(?]/\\b/g;
$searchString =~ s/^(.*)$/\\b$1\\b/go if $options->{'wordboundaries'};
- my $match_code = "return \$_[0] =~ m/$searchString/o";
- $match_code .= 'i' unless ($options->{casesensitive});
- my $doMatch = eval "sub { $match_code }";
+
+ my $doMatch;
+ if ($options->{casesensitive}) {
+ $doMatch = sub { $_[0] =~ m/$searchString/o };
+ } else {
+ $doMatch = sub { $_[0] =~ m/$searchString/oi };
+ }
+
FILE:
foreach my $file ( @$topics ) {
next unless open(FILE, "<$sDir/$file.txt");
I'll have to track down how to submit TWiki bugs... Update 2: Another search issue - in the persisted view, the search page never gets re-rendered (ie. after making one successful search, all future searches appear to have identical results).
I didn't have time to find if that was a problem in the view code or the pure pearl search, but it was easy enough to make sure a new cgi was spawned per search request by adding the following at the end of the VirtualHost: <LocationMatch "WebSearch">
SetHandler cgi-script
</LocationMatch>
Conveniently the FCGI script works fine as a regular one-shot cgi, and since LocationMatch is processed after FilesMatch by Apache, this overrides the fcgid handler setting.
06:51 PM, 20 Jul 2008 by Mark Aufflick Permalink | Comments (0) |
Archive
November 2008 October 2008 September 2008 August 2008 July 2008 June 2008 May 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 September 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 October 2006 September 2006 August 2006 July 2006 June 2006 May 2006 April 2006 March 2006 February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 February 2005 January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 Notifications Request notifications
Recent Comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Request notifications