#!/usr/bin/perl use common::sense; use DBI; use DBD::Pg qw/PG_ASYNC/; use IO::Select; print "Status: 200\nContent-Type: text/plain\n\n"; $|=1; $|=0; # flush my $dbh; $SIG{TERM}=sub { $dbh->pg_cancel if $dbh and $dbh->{pg_async_status}==1; }; $dbh=DBI->connect('dbi:Pg:dbname=r2', 'ipp', undef, {RaiseError=>1}); my $ sth = $ dbh-> prepare ('select burncpu (?)' {pg_async=>PG_ASYNC}); $sth->execute((($ENV{QUERY_STRING}+0) || .5).'s'); my $sel=IO::Select->new($dbh->{pg_socket}); while( $sel->can_read and !$dbh->pg_ready) { warn "not ready, yet. keep polling\n"; } if( $dbh->{pg_async_status}==1 ) { $dbh->pg_result; while( my $row=$sth->fetchrow_arrayref ) { print "@$row\n"; } } elsif( $dbh->{pg_async_status}==-1 ) { warn "query cancelled\n"; }