FU

 view release on metacpan or  search on metacpan

FU.pm  view on Meta::CPAN

        $c->{fcgi_obj} ||= $c->{listen_proto} eq 'fcgi' && FU::fcgi::new(fileno $c->{client_sock}, $c->{proc});

        if ($c->{monitor} && _monitor) {
            log_write "File change detected, restarting process.\n" if debug;
            passclient;
        }

        setstate 'working';
        _do_req $c;

        $c->{client_sock} = $c->{fcgi_obj} = undef if !($c->{fcgi_obj} && $c->{fcgi_obj}->keepalive);

        $count++;
        passclient if $c->{max_reqs} && $count >= $c->{max_reqs};
    }
}


sub _supervisor($c) {
    my ($rsock, $wsock) = IO::Socket->socketpair(IO::Socket::AF_UNIX(), IO::Socket::SOCK_STREAM(), IO::Socket::PF_UNSPEC());

FU.pm  view on Meta::CPAN

Start a local web server on the given address. I<addr> can be an C<ip:port>
combination to listen on TCP, or a path (optionally prefixed with C<unix:>) to
listen on a UNIX socket. E.g.

  ./your-script.pl --http=127.0.0.1:8000
  ./your-script.pl --http=unix:/path/to/socket

B<WARNING:> The built-in HTTP server is only intended for local development
setups, it is NOT suitable for production deployments. It has no timeouts, does
not enforce limits on request size, does not support HTTPS and will never
adequately support keep-alive. You could put it behind a reverse proxy, but it
currently also lacks provisions for extracting the client IP address from the
request headers, so that's not ideal either. Much better to use FastCGI in
combination with a proper web server for internet-facing deployments.

=item FU_FCGI=addr

=item --fcgi=addr

Like the HTTP counterpart above, but listen on a FastCGI socket instead. If
this option is set, it takes precedence over the HTTP option.

Nginx and Apache will, in their default configuration, use a separate
connection per request. If you have a more esoteric setup, you should probably
be aware of the following: this implementation does not support multiplexing or
pipelining.  It does support keepalive, but this comes with a few caveats:

=over

=item * You should not attempt to keep more connections alive than the
configured number of worker processes, otherwise new connection attempts will
stall indefinitely.

=item * When using C<--monitor> mode, the file modification check is performed
I<after> each request rather than before, so clients may get a response from
stale code.

=item * When worker processes shut down, either through C<--max-reqs> or in
response to a signal, there is a possibility that an incoming request on an
existing connection gets interrupted.

FU.xs  view on Meta::CPAN

    ctx->fd = fd;
    ctx->maxproc = maxproc;
    ctx->reqid = ctx->keepconn = ctx->len = ctx->off = 0;
    ST(0) = fu_selfobj(ctx, "FU::fcgi");

void read_req(fufcgi *ctx, SV *headers, SV *params)
  CODE:
    ST(0) = sv_2mortal(newSViv(fufcgi_read_req(aTHX_ ctx, headers, params)));
    ctx->off = ctx->len = 0;

void keepalive(fufcgi *ctx)
  CODE:
    ST(0) = ctx->keepconn ? &PL_sv_yes : &PL_sv_no;

void print(fufcgi *ctx, SV *sv)
  CODE:
    STRLEN len;
    const char *buf = SvPVbyte(sv, len);
    fufcgi_print(aTHX_ ctx, buf, len);

void flush(fufcgi *ctx)

FU/Pg.pm  view on Meta::CPAN

C<$major * 10000 + $minor>. For example, returns 170002 for PostgreSQL 17.2.

=item $conn->lib_version

Returns the libpq version in the same format as the C<server_version> method.
Also available directly as C<FU::Pg::lib_version()>.

=item $conn->status

Returns a string indicating the status of the connection. Note that this method
does not verify that the connection is still alive, the status is updated after
each command. Possible return values:

=over

=item idle

Awaiting commands, not in a transaction.

=item txn_idle

FU/Pg.pm  view on Meta::CPAN


=item $conn->query_trace($sub)

Set a subroutine to be called on every query executed on this connection. The
subroutine is given a statement object, refer to the C<$st> methods below for
the fields that can be inspected. C<$sub> can be set to C<undef> to disable
query tracing.

It is important to not hold on to the given C<$st> any longer than strictly
necessary, because the prepared statement is not closed or reclaimed while the
object remains alive. If you need information to remain around for longer than
the duration of the subroutine call, it's best to grab the relevant information
from the C<$st> methods and save that for later.

Also worth noting that the subroutine is called from the context of the code
executing the query, but I<before> the query results have been returned.

The subroutine is (currently) only called for queries executed through C<<
$conn->exec >>, C<< $conn->sql >>, C<< $conn->SQL >> and their C<$txn> variants;
C<< $conn->copy >> statements and internal queries performed by this module
(such as for transaction management, querying type information, etc) do not

FU/Pg.pm  view on Meta::CPAN



=head1 Transactions

This module provides a convenient and safe API for I<scoped transactions> and
I<subtransactions>. A new transaction can be started with C<< $conn->txn >>,
which returns an object that can be used to run commands inside the transaction
and control its fate. When the object goes out of scope, the transaction is
automatically rolled back if no explicit C<< $txn->commit >> has been
performed. Any attempts to run queries on the parent C<< $conn >> object will
fail while a transaction object is alive.

  {
    # start a new transaction
    my $txn = $conn->txn;

    # run queries
    $txn->sql('DELETE FROM books WHERE id = $1', 1)->exec;

    # run commands in a subtransaction
    {

FU/Pg.pm  view on Meta::CPAN


=item $copy = $conn->copy($statement)

=item $copy = $txn->copy($statement)

Execute C<$statement> and return a C<FU::Pg::copy> object that lets you
transfer data to or from Postgres.

It is not possible to execute any other queries on the same connection while a
copy operation is in progress. When used on a transaction object, C<$txn> must
be kept alive long enough to finish the copy operation.

=back

A C<$copy> object supports the following methods:

=over

=item $copy->is_binary

Returns true if the transfer is performed in the binary format, false for text.

t/pgconnect.t  view on Meta::CPAN

    ok $st->get_text_params;
    ok $st->get_text_results;

    $conn->query_trace(undef);
    $conn->exec('SELECT 1');
    is scalar @log, 0;
};

{
    my $st = $conn->sql("SELECT 1");
    undef $conn; # statement keeps the connection alive
    is $st->val, 1;
}

done_testing;



( run in 0.923 second using v1.01-cache-2.11-cpan-483215c6ad5 )