Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71117 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40230 invoked from network); 13 Jan 2014 23:50:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2014 23:50:20 -0000 Authentication-Results: pb1.pair.com header.from=mike.php.net@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mike.php.net@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: mike.php.net@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-la0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:35904] helo=mail-la0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/D9-21529-BBB74D25 for ; Mon, 13 Jan 2014 18:50:20 -0500 Received: by mail-la0-f41.google.com with SMTP id mc6so1968771lab.0 for ; Mon, 13 Jan 2014 15:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=GMzCJMem0WwhJAVT8wEGUS5MHWjkGkFQyI2MhuRt+GI=; b=LeE6/M3JeoPLN4dcJhdxB90mj8xq5g2z+LjDdg28E6ZDO4bdyej+RpF7yylgyakgDM poY/NF29S9dXgBsT2FbQSrWGtoGn3RorVFmGSUYcQg6FsOsGtgI2XL/8xQMxRGNpmWyg lR5EryzXW58b+zZvS0ZPoeelMwrLqTkU+FuF8bXkFlHQJiYihH/mYCROyTcZoi8+chQQ UzVn9j8ZafUq0ANvPcA2yG9kw/+FhCgISgDRgR31OBn7Ykc8gZfpOPBIBceQUGCZ2PBw V6BLOHDO331ibVXvhZ34/Xu3mypEkZ81PR8unuaAzIn1CWAze3Msq73g6fvcNjEr1vsq yNFA== MIME-Version: 1.0 X-Received: by 10.152.180.66 with SMTP id dm2mr47891lac.88.1389657016284; Mon, 13 Jan 2014 15:50:16 -0800 (PST) Sender: mike.php.net@gmail.com Received: by 10.114.80.230 with HTTP; Mon, 13 Jan 2014 15:50:16 -0800 (PST) Received: by 10.114.80.230 with HTTP; Mon, 13 Jan 2014 15:50:16 -0800 (PST) In-Reply-To: References: Date: Tue, 14 Jan 2014 00:50:16 +0100 X-Google-Sender-Auth: c5EZw3R3huSWbuq7qOUIPlJ4KcM Message-ID: To: Daniel Lowrey Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11345896d0b8ed04efe2bcbf Subject: Re: [PHP-DEV] Non-Blocking PostgreSQL From: mike@php.net (Michael Wallner) --001a11345896d0b8ed04efe2bcbf Content-Type: text/plain; charset=UTF-8 On 13 Jan 2014 14:52, "Daniel Lowrey" wrote: > > Hi, internals! > > Since Yasuo mentiond ext/pgsql ... > > The Postgres extension allows for some limited "async" functionality but it > simplifies things for users by blocking on socket writes and offers no > potential for asynchronous connection attempts. This makes the extension > unusable inside non-blocking event loops. Because non-blocking is pretty > much the only thing I do these days I spent a bit of time over the holidays > I to address these issues. > > There is a fully-functioning implementation here that addresses all of my > needs: > > https://github.com/rdlowrey/php-src/compare/pgsql-async > > Some brief (simple) usage examples can be seen here: > > https://gist.github.com/rdlowrey/8114597 > > I plan to add some tests and merge the changes for 5.6/master but I just > wanted to check to make sure no one has feedback/suggestions prior to doing > so. > > > A summary of changes: > > - No BC breaks, compatible with very old libpq versions > - Several new functions mapping to PQ_* functions > - Expose the underlying socket via a new pg_socket($db) function. The > resulting stream has no behavior *except* to allow casting to a descriptor > for IO notifications via select/epoll/kqueue etc. > - Closing the exposed stream has no effect on the associated pgsql > resource. It's impossible to break the existing API using the exported > descriptor handle. > - Connections may now be established asynchronously as a result of > pg_socket(), pg_connect_poll() and newly exposed constants. > - This patch adds an optional boolean $shouldBlock=TRUE to the few methods > that currently block on writes to retain BC while allowing users to > manually manage IO in non-blocking environments. > > -- New Functions -- > > - int pg_connect_poll(resource $pgsql) > - resource pg_socket(resource $pgsql) > - int pg_consume_input(resource $pgsql) > - int pg_flush(resource $pgsql) > > -- Altered Functions -- > > Each of the existing "async" send methods now accept an optional boolean > $should_block = TRUE parameter to control the undesirable blocking send > behavior. > > - pg_send_execute > - pg_send_prepare > - pg_send_query_params > - pg_send_query > > -- New Constants -- > > - PGSQL_CONNECT_ASYNC > - PGSQL_CONNECTION_STARTED > - PGSQL_CONNECTION_MADE > - PGSQL_CONNECTION_AWAITING_RESPONSE > - PGSQL_CONNECTION_AUTH_OK > - PGSQL_CONNECTION_SSL_STARTUP > - PGSQL_CONNECTION_SETENV > - PGSQL_POLLING_FAILED > - PGSQL_POLLING_READING > - PGSQL_POLLING_WRITING > - PGSQL_POLLING_OK > - PGSQL_POLLING_ACTIVE > > If anyone has any thoughts please let me know! Check this out whike you're st it: http://pecl.php.net/package/pq --001a11345896d0b8ed04efe2bcbf--