Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71109 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81051 invoked from network); 13 Jan 2014 13:52:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2014 13:52:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=rdlowrey@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rdlowrey@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: rdlowrey@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-ie0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:52885] helo=mail-ie0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/E0-10820-1AFE3D25 for ; Mon, 13 Jan 2014 08:52:34 -0500 Received: by mail-ie0-f173.google.com with SMTP id u16so5527695iet.18 for ; Mon, 13 Jan 2014 05:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=r6gbWeIp/JFOxkEBnxbY/b1p6wD0f5B0WRP51cCv7lM=; b=GaG4R5Keu0UjyTQe7vWsaloLvboPHdP+zISBnYR8FlRjwhb72Y3TMEDo8EmzOPVp9F qP8MQxS4ipEyhxZ5SsGNwiufZzRPW9U76D13cAxSTzGddQb/8C5LXB/JD1gFXw91ZPjK GlPMsMMb+/5cJxY7P+fz1uvYrblxC7wIX2FJHHTQi56qOw460o9dJ65XH3MAk7Aq9oLW eupaICPmWjszYo8avju7cIhlC3gCt02qWgc5Tq6TaKaX3xCtuXZFU/91PXc8nkcvsQOu aOiChA+1noovHsIpuJbOFeZnEDGOkbpA7ZHTQVyancvLhdL5s+8KsWMLwcV0Gc1dJ4Hl sYHQ== MIME-Version: 1.0 X-Received: by 10.50.222.225 with SMTP id qp1mr18556144igc.49.1389621151062; Mon, 13 Jan 2014 05:52:31 -0800 (PST) Received: by 10.50.29.140 with HTTP; Mon, 13 Jan 2014 05:52:30 -0800 (PST) Date: Mon, 13 Jan 2014 08:52:31 -0500 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=14dae934100f15058b04efda63f4 Subject: Non-Blocking PostgreSQL From: rdlowrey@gmail.com (Daniel Lowrey) --14dae934100f15058b04efda63f4 Content-Type: text/plain; charset=ISO-8859-1 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! --14dae934100f15058b04efda63f4--