Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107512 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24080 invoked from network); 11 Oct 2019 17:38:15 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 17:38:15 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 17CBB2D08EE for ; Fri, 11 Oct 2019 08:21:26 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 11 Oct 2019 08:21:25 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id x80so7342694lff.3 for ; Fri, 11 Oct 2019 08:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wH7Z/8rg+qyPXpZ9G0SpjQX2r9SvUMgQyrFX4IoBEGs=; b=hEfMDPC0l2g/yNIapsyMSeN82S2JXp/UHHhBg7O1sUa20v0iTXeXdg1GGO+PMCIzxz Ma+cXOFK/IPgfeRTvBY25M1eRBOgk0TM8qC0mKo+nxhu603itUHEFDRs5QbBhKnRWmaR 0VG/ZjpqCtQUb2iO0z3wKKowBGGaRRC8A26pFmXlHrlsBHVb0L3NGqFl2u1V/JYTju7u DIgBOV86BreU6Aqc3WLRYrRa7qM3bg+BpXhSRNwCYOsEVYjJm9rHOU0oZ7GHoCcxGVue XjwR4VXHrBGniTFNzdZIzQn3ij2F/ttiHil3YOThMfEPkP9kCoAOhZSi6m/d7yS0sIE7 R8Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wH7Z/8rg+qyPXpZ9G0SpjQX2r9SvUMgQyrFX4IoBEGs=; b=ofv22SPymfDmtnXfM/7qyPeyJSb6aH7TPso+ORNqwn9pED8jwO6L1oosI+KjrpkddI TEAf5D2QQIPV94tQppvSOdM19h8k61YpkdnyMdxbDifPBjbiC+2JDcDnNYZYPkg77eKm BIKXc7hZBnP2HOJ3t7FMKdHRpYBpJ68eTJ2AXgtWM0VGUycQOeYUJWgPKwCuSsinR22Y qd8WDQ7v4aapUvcwAkAfRFkhEbcXghwOA1pX8otDiom6cODBr+2h1lKfIatInVhVWpTY dHS4x3lR7VxKQRhV1v4KYpOR0KDzzXLyFNL4KlPd0saX/1sDAKqcHMUcfDnP8uY2FHE0 +c8g== X-Gm-Message-State: APjAAAV+iniL9T6hILc5dIwdHp3G1Nmbg3sthJT5VVEcE5vPLrDTLB03 tekNhrSY5F+Z2sH7ENS/IgGeIwrSsSs7RipUWLbLiLDzhUE= X-Google-Smtp-Source: APXvYqwIF9FaFPWYcqdeG8qpUCb6pCR6n2OfugMGoGudczjfDq0SzoK6L5p65qbScUBkGcerMGTHTh7BJfF0R54ACjw= X-Received: by 2002:ac2:4c99:: with SMTP id d25mr9766256lfl.112.1570807284258; Fri, 11 Oct 2019 08:21:24 -0700 (PDT) MIME-Version: 1.0 References: <2406F2E7-CD65-4E30-A98C-C09FB52B4F2B@trowski.com> In-Reply-To: Date: Fri, 11 Oct 2019 17:21:07 +0200 Message-ID: To: Marcio Almada Cc: Aaron Piotrowski , PHP internals Content-Type: multipart/alternative; boundary="000000000000305cd00594a41207" X-Envelope-From: Subject: Re: [PHP-DEV] exit() via exception From: nikita.ppv@gmail.com (Nikita Popov) --000000000000305cd00594a41207 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Oct 11, 2019 at 5:13 PM Marcio Almada wrote= : > Hi! > > > > I don't believe atexit applies to os._exit(). In any case, I agree th= at > > > this is something we're currently missing -- we should probably add a > > > pcntl_exit() for this purpose. It should be noted though that this is > > > really very different from exit(), which is still quite graceful and > usable > > > in a webserver context, while a hypothetical pcntl_exit() would bring > down > > > the server process. As the Python docs mention, the primary use-case > would > > > be exiting from forked processes without going through shutdown, whic= h > has > > > also recently come up in https://github.com/php/php-src/pull/4712. > > > > > > > > >> If we bind `exit()` and `die()` to a catchable exception how would w= e > > >> still have the scenario 2 available > > >> on PHP land without a BCB? :) > > >> > > > > > >> I have one simple suggestion: Introduce `EngineShutdown -> Throwable= `, > > >> bind `exit|die` to it but disallow > > >> `catch(\EngineShutdown $e)` at compile time. This would allow keepin= g > > >> backwards compatibility to > > >> scenario 2 without messing with our current exception hierarchy. > > >> > > > > > > I think the options are basically: > > > > > > 1. Making EngineShutdown implement Throwable, which would make existi= ng > > > catch(Throwable) catch it -- probably a no-go. > > > > > > 2. Making EngineShutdown not implement Throwable, which means that no= t > all > > > "exceptions" implement the interface, which is rather odd. It still > allows > > > explicitly catching the exit. > > > > > > 3. Introducing a function like catch_exit(function() { ... }). This > would > > > still allow catching exits (for phpunit + daemon use cases), but the > fact > > > that this is actually implemented based on an exception would be > hidden and > > > the only way to catch the exit is through this function. > > > > > > 4. Don't allow catching exits at all. In this case the exception is > just an > > > implementation detail. > > > > > > Nikita > > > > +1 for option 3. > > So maybe it narrows down to: > > Is there an essencial attempt to improve `exit()` handling from the > userland perspective or should the focus be solely on solving the > memory management issue pointed out in the beginning of the thread? > > If the scope is to also improve userland, option 3 could be the way to > go indeed but I confess to do not be a fan of another callback > registering thing... it feels hard to predict when you consider: > > ``` > catch_exit(function(){ > exit(); // what happens here? We still have to guarantee `exit` to > halt at some point. > }); > ``` > > And what are the interactions with `register_shutdown_function`? I > suppose the `catch_exit` stack has to be run before the > `register_shutdown_function` stack? Considering the behavior in the > docs. > I think I was a bit unclear in how the catch_exit() function is intended to work: It's not an atexit handler, it's basically a try/catch block for exits. $exitExceptionOrNull =3D catch_exit(function() { // Run code that may contain exit() here }); or possibly even more explicitly as: catch_exit(function() { // Run code that may contain exit() here }, function($exitCode, $exitMessage) { // This is called if an exit() occurred }); I like option 4 much more for now. It allows tackling the root issue > and still leaves possibilities open regarding how the exception > hierarchy could be and how the handling of `exit` could happen > (through a catch at userspace or callback registering). > I guess we should do that as the first step in any case ... everything else would be extensions on top of that, but this would be the main technical groundwork. Nikita > > > > EngineShutdown could be a special exception to the engine, being handle= d > like an exception internally, but not implement Throwable and therefore n= ot > an exception from user-land's point-of-view. > > > > EngineShutdown could be added to the list of "throwables", but forbid > instigation in user-land. > > > https://github.com/php/php-src/blob/db233501ff9d56765ef4a870b777a643c2136= 711/Zend/zend_exceptions.c#L909-L916 > > > > No catch block would catch it, because it wouldn't implement Throwable > nor extend Exception or Error. > > > > Very elegant solution! > > PS: Naming things is hard, but `Throwable` could not have been a > better choice in retrospect. Ty ;) > > > Aaron Piotrowski > > > > M=C3=A1rcio > --000000000000305cd00594a41207--