[Pdx-pm] Q about ithreads && signals

Tom Phoenix rootbeer at redcat.com
Sun Nov 17 15:42:04 CST 2002

On Sun, 17 Nov 2002, Joshua Hoblitt wrote:

> The idea is to have a query to this web-server happen every 10 seconds
> (10 seconds from query start to query start).  I can't think of any
> clean way to do that without signals. (could burn up alot of cpu power
> watching the clock I guess)

It's not a lot of cpu power. It's not even a need for threads and signals.
Dress this up as needed:

  my $next_query = time + 10;
  while (1) {
    # Wait until it's time...
    my $now = time;
    if ($now < $next_query) {
      # It's not time yet
      sleep($next_query - $now);
    } elsif ($now > $next_query) {
      # Missed the moment. Do whatever you need to do for that case.
    $next_query += 10;

If the source data is really changing every ten seconds, though, maybe
http isn't the best way to transfer it from site to site. Can you put a
program onto the source machine? A very simple server could do the trick:
A client connects to its port, and the server sends the data down the pipe
every time it changes. Pretty straightforward TCP socket stuff should do
the trick.

Good luck with it!

--Tom Phoenix

More information about the Pdx-pm-list mailing list