Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Search Timer

Quote Reply
Search Timer
Well I had what I thought was a good idea but I am having a bit of trouble (as usual) so some tips would be appreciated....

I am trying to time searches and then show the time taken on the search results page.

So...I thought Id start by adding this code to search.cgi...

sub _time_start {
# ------------------------------------------------------------------
# Start a timer.
#
BEGIN { local $@; eval { require Time::HiRes; import Time::HiRes qw/time/; }; }
$TIME_START = time;
}


...then I thought I'd add _time_start(); in sub main. I then gave it a test by searching for anything but it gave me an internal server error. So I removed _time_start(); from sub main and tested again but I still got the error.

If that had worked I was planning on adding...

sub _time_display {
# ------------------------------------------------------------------
# Return time results.
#
my $end = time;
my $elapsed = sprintf ("%.2f", $end - $TIME_START);
return $elapsed;
}


...as a global called <%time%>, so that when I added <%time%> to search_results.html, it would tell me how long the search had taken.

What am I doing wrong?...both chunks of code are taken straight from nph_build.cgi so the syntax is correct!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Check your error logs!! That's the best place for help.

Did you declare $TIME_START as a global variable? You would need to define it at the start of the program, external to any block, since you are allowing two routines that are external to any block to use it.

Also, you have this:

BEGIN { local $@; eval { require Time::HiRes; import Time::HiRes qw/time/; }; }

In sub _time_start , but you have it scoped as a run-time 'require', which would most likely not make it available to:

my $end = time;

in sub _time_display

Just some thoughts. Check your error log. It will most likely tell you.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Search Timer In reply to
Oh...this is a little over my head...

In Reply To:
Did you declare $TIME_START as a global variable?
Does that mean I have to create a global called <%TIME_START%> with the code from...
sub _TIME_START {
......?

Ill check my logs....thanks again Pugdog!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
The <% %> is only the way to display the variable in the template. It's not a variable or global in and of itself.

In the code itself you need to declare the variables. I think you need to take a step or two backwards, out of the template routines. All this needs to be in the search.cgi script. Initialize it when you start, subtract it out when you end, and stuff it into $rec-> (or even $IN->) to return the value to the template.

Whatever you stuff into the hash sent to the template routine will turn into the tag.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Search Timer In reply to
OK so do I add the code straight into sub main { or do I add it to the bottom of search.cgi and call it in sub main { using...

_TIME_START();

_TIME_END();

?

Sorry for being so irritating..!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
You can do it either way, but it's probably easier just to put the start code at the begining of main, and the end code just before you print out the templates. Since you don't really need to count the time to print the templates in the search anyway.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Search Timer In reply to
Thanks....Ill give it a whirl!

Youll nearly be up to Anthrorules 10,000 posts after youve finished dealing with all my problems!!!!!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Hi,

Try replacing:

my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'search_results', \&query, {});

with:

_time_start();
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'search_results', \&query, {});
$results->{query_time} = _time_display();

and copy and paste _time_start and _time_display to search.cgi and add:

use vars qw/$TIME_START/;

to your code. You can then access the time using <%query_time%>.

A plugin would be a better solution, using a pre hook to start the timer and a post hook to stop the timer (as then you don't need to edit any code).

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Search Timer In reply to
Oh thankyou Alex.

I will try that.

I will have to let someone else make that plugin...Im not up to that standard yet :)
(If Im feeling adverturous I may give it a go!)

Thanks again...hope you had a nice christmas!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Excellent Alex...thanks it worked 1st time!

However...it only seems to count in seconds so I get a result like 1.0 or 0.0

Is there anyway to produce a more accurate time?

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
You need to install the Time::HiRes module. That will make it time to the miliseconds.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Search Timer In reply to
errrr......how do I do that?

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Hi,

It's something your ISP needs to do, or you need shell access:

perl -MCPAN -e 'install Time::HiRes'

will do the trick.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Search Timer In reply to
Oooooo....

Well I am trying to setup my domain so I can access it using SSH but ive never done it beofre and dont really know what to do.

My domains control panel asks me for an RSA Key but I dont know how to generate it and I dont know which SSH software to use?

Could you give me some advice please?

Thanks..

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Hi,

Try http://www.vandyke.com for SecureCRT, that's what I use. For a free alternative (not sure if it does RSA though), try: http://www.chiark.greenend.org.uk/~sgtatham/putty/.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Search Timer In reply to
Sorry....
Quote Reply
Re: Search Timer In reply to
Oh thats a coincidence....I just downloaded both of those!

With the first one you mentioned I could not find how to generate the key and I just tried the second one (putty) and it logged me into my server.

How did it do that when I hadnt submitted a RSA code to my server?

I logged in and entered the code you supplied but when I presses return it just showed a ">" on a new line....did it not work or is that correct?

Ahh....I get this error when I try to run nph-build using SSH...

GT::SQL::Condition (17619) : Unknown method '_as_hash' called at GT::SQL::Condition.pm line 262 - Perhaps you meant to call 'as_hash'

???



Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
OK Im a little bit further on now but I am being told this....

We need to reconfigure CPAN.pm due to the following uninitialized parameters...

CPAN-home, build_dir .....lots more....

The CPAN module needs a directory of its own...
I see you laready have a directory /home/audio/.cpan
Shall we use it as a general CPAN build and cache directory?

CPAN build and cache directory? [/home/audio/.cpan] *there*

What do I type *there*????


Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Hmmmm this is all new to me...

I got further again...

It kept asking me qn's like what my favourite CPAN site is etc..

It eventually said that it cant fetch about 3-4 different files and said "Cant install Time::HiRes because I dont know what it is".

If I gave you my login details would you be kind enough to try for me?
Thankyou.

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Heh...I could get used to this new found skill!

I downloaded MyConfig.pm to my PC and this is what it said..

$CPAN::Config = {
'build_cache' => q[10],
'build_dir' => q[/home/audio/.cpan/build],
'cpan_home' => q[/home/audio/.cpan],
'ftp' => q[/usr/bin/ftp],
'ftp_proxy' => q[],
'getcwd' => q[cwd],
'gzip' => q[/usr/bin/gzip],
'http_proxy' => q[],
'inactivity_timeout' => q[0],
'index_expire' => q[1],
'inhibit_startup_message' => q[0],
'keep_source_where' => q[/home/audio/.cpan/sources],
'lynx' => q[/usr/bin/lynx],
'make' => q[/usr/bin/make],
'make_arg' => q[],
'make_install_arg' => q[],
'makepl_arg' => q[],
'ncftp' => q[/usr/bin/ncftp],
'no_proxy' => q[],
'pager' => q[/usr/bin/less],
'shell' => q[/bin/bash],
'tar' => q[/bin/tar],
'unzip' => q[/bin/unzip],
'urllist' => [q[http://www.cpan.com]],
'wait_list' => [q[wait://ls6.informatik.uni-dortmund.de:1404]],
};
1;
__END__


The problem was cpan.com......it should be cpan.org

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
PHEW.....

My host installed it for me and it works!!!!

Just performed a search and it said

"Search took 0.68 seconds"....hehe

THANKS ALEX

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Search Timer In reply to
Hi,

Im not sure whether this is a bug for all users or just me because Ive been modding nph-build but when I tried to run nph-build.cgi from SSH it told me about an error in Condition.pm.

Original Code:
sub as_hash {
my $cond = shift;
ref $cond eq 'HASH' and return $cond;
my $href = {};
foreach my $arr (@{$cond->{cond}}) {
if (ref $arr eq ref []) {
$href->{$arr->[0]} = $arr->[2];
}
else {
my $h = _as_hash ($arr);
for my $k (keys %{$h}) {
$href->{$k} = $h->{$k};
}
}
}
return $href;
}

1;


...fixed code:
sub as_hash {
my $cond = shift;
ref $cond eq 'HASH' and return $cond;
my $href = {};
foreach my $arr (@{$cond->{cond}}) {
if (ref $arr eq ref []) {
$href->{$arr->[0]} = $arr->[2];
}
else {
my $h = as_hash ($arr);
for my $k (keys %{$h}) {
$href->{$k} = $h->{$k};
}
}
}
return $href;
}

1;


The underscore needed to be removed.

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)