Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85742 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42807 invoked from network); 7 Apr 2015 15:31:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2015 15:31:56 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.216.49 mail-vn0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:34377] helo=mail-vn0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/91-33115-968F3255 for ; Tue, 07 Apr 2015 11:31:54 -0400 Received: by vnbf190 with SMTP id f190so9430725vnb.1 for ; Tue, 07 Apr 2015 08:31:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Z9jO/8Hg1Mc0OCRnAfNVd9Q+exlD3cMbe+B0Iy93PBM=; b=WgU/RiSwPgyXJFBqFqzSwMRpQHDJDxWK7P58GOvo35rlcaSMwCeJ+idPranKlmTPwb ilO0Rdoe7usj7IxUJeOSMoMEtKSw5pAEhXUSxrqzqDrIeE0i6tfZXDVFU+ncFh9BQz3q I7dnBvEh926kyttJNedfj/56lszOr1kIfO+iYG4l/9Wcl9NoLhsN5tCqb7/GN26Qc4Gf +t/3kKkEe3HObYdJe3+pBjJ0d/gpcUUtW7Ib7V4rjOtVDa+ewfjQ77qA149K6lIrtAqc c1I53svIlH2Hc7uERdit8+GkTvAoGbs/u4oSDdB3Zqs8u4hamdQ9MHxiz1FXsD0UE43+ /Ibg== X-Gm-Message-State: ALoCoQmXC8/ih+pjJ0mJbna+PnJ1MtVwD9ZagFsZRjbBICcxzljq5TxegK2dbAHmtxUOHHPxwpKM6mu3X6hJTDVsVs128xrOVqTkv9qSX+IYpA1Ixpz5LVLc13lFgiZferIeYS+BFj1/XX9ptMweMLL6SIhGD7zJWA== MIME-Version: 1.0 X-Received: by 10.52.78.35 with SMTP id y3mr13751249vdw.5.1428420710768; Tue, 07 Apr 2015 08:31:50 -0700 (PDT) Received: by 10.52.248.36 with HTTP; Tue, 7 Apr 2015 08:31:50 -0700 (PDT) In-Reply-To: <5523F025.5070407@hristov.com> References: <5523DF0E.6000500@hristov.com> <5523F025.5070407@hristov.com> Date: Tue, 7 Apr 2015 18:31:50 +0300 Message-ID: To: Andrey Hristov Cc: PHP internals , Nikita Popov Content-Type: multipart/alternative; boundary=001a113403820e3abb0513241d31 Subject: Re: [PATCH] Tick functions (on C level) with state From: dmitry@zend.com (Dmitry Stogov) --001a113403820e3abb0513241d31 Content-Type: text/plain; charset=UTF-8 This is really interesting, but I think use of "ticks" for asynchronous functions is bad approach. A month or two ago I published a PoC for safe interrupt handling. https://github.com/php/php-src/compare/master...dstogov:interrupt Actually it's already partially committed to support timeout handling on Windows. This idea may be extended to implement cooperative-multitasking, asynchronous callbacks, signal handlers, etc... I didn't continue work on it yet, because it's too later for PHP-7.0 and I have a lot of other PHP-7 related work. If you like to implement MYSQLI_ASYNC PoC now - just include your ticks extension there. If we accept it, we will accept all together. Thanks. Dmitry. On Tue, Apr 7, 2015 at 5:56 PM, Andrey Hristov wrote: > Hi Dmitry, > On 7.04.2015 16:33, Dmitry Stogov wrote: > >> Hi Andrey, >> >> I didn't get why do you need this extension and how it's going to be used. >> > > I would like to implement (I have a PoC for this too), asynchronous query > handlers in mysqli@mysqlnd. Currently it is possible to have some > asynchronisity like > > $c = mysqli_query("....", MYSQLI_ASYNC); > > // do some work > // poll with mysqli_poll > > // synchronise with mysqli_reap_async_query > > // fetch data > > I would like to skip the //poll and in some cases the //synchronise part > and have > > $c = mysqli_query("....", MYSQLI_ASYNC, > function () use ($c) { > $res = mysqli_reap_async_query($c); > // do something with the result > } > ); > > The closure can also set some global flag, and somewhere in the "main" > thread it one can synchronize on it. It can also use [class, method] > callback syntax. For example one can subclass class mysqli, add some status > variables for state, and a method to pass to mysqli_query()/ > mysqli::query(). > > mysqlnd registers a small tick function, that does select, and if there is > data to be read the closure is called. Another closure for handling an > error should be added too (but I don't have it my PoC). > > Hope this helps to enlighten my intentions. > > Best, > Andrey > > > Thanks. Dmitry. >> >> On Tue, Apr 7, 2015 at 4:43 PM, Andrey Hristov > > wrote: >> >> Hi, >> I would like to hear comments about a small change to the low-level >> tick functionality (main/php_ticks.c) to add state to when calling a >> C tick function >> The patch is alive at : http://pastebin.com/0zhVNxaY >> >> Currently a C tick function gets as a parameter just the number of >> ticks, and can't preserve state between calls. On PHP level one can >> use closures to mitigate this, but in the C world we don't have this >> luxury. >> >> Any comments are very welcome. If possible to get in PHP7. >> >> >> Cheers, >> Andrey >> >> >> > --001a113403820e3abb0513241d31--