Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107510 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20309 invoked from network); 11 Oct 2019 17:30:50 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 17:30:50 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id DB0532D2056 for ; Fri, 11 Oct 2019 08:14:00 -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,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-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) (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:14:00 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id v38so8987084edm.7 for ; Fri, 11 Oct 2019 08:14:00 -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:content-transfer-encoding; bh=OrjVR8cawsw//iVo653XbykcjGt7xOJYABEJNd4KP+0=; b=eMR8CnrPCYaQZRkDG/jJ1DPUwdqEBX+XFp6rF3ENFjzVhBWXSuHNvczvqDFkOWaT7t tmTVJUdSF6w678Vz1T9xUT+IzpYbSHfC/wIHa+LG2AEnh2MaL5UV+bZHET1pTZDI2olU IMkQLcElSC3ptplX3nsx7hYHVmJmLLqFhh7+TQT8qcjSfvmNp70xrqVjO/KmgMlZDJ+L 9BdlYj7ZyMGBtvOmmiBbPapZ73OiaD2BirVt1abAICqbHs8VjyALvKRyw0MUkXe9U47T RAKU7Ds6c2HnyRAT73fzoFKEwUQg2JIEZs1MSI65Y9RE5Y+ynQ8YmffkpFixw5nKQPUD /RJg== 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:content-transfer-encoding; bh=OrjVR8cawsw//iVo653XbykcjGt7xOJYABEJNd4KP+0=; b=FmAbD+TfIzMLhBMbFCb3F3nU+Ulb3IOc48WiBZd+NVgyX5FKmPUPM8U3744Z3gx9/T 4MuqZtF/S1HOKGTU2NP5cVmYPkOD3r3uaq6QClraK1kkgNIt/dTeVb+nK9qiJ4AdHrDm Z9Cv69vt4/7qIxHjh0nFMWYEcELypqMSbcM5kO4O1o09ORKJ3KJw0UFbLwYTnSGLMx02 shTxsNRRQclzu6POteKdasYFazsOggGf4zhu8Ev+PqjwxqBPhaAWGamljnTAPDHtufCR 29EoMFzLrJ9a1kx+AoDVSqjdRO0K1rhZFbbgLbJZ3EBZ8ddaDw/awqp9iAAhQOANT8d0 Yliw== X-Gm-Message-State: APjAAAV/u6DJs4D76WdQvZ3foq9SQKLts9WK77eMLcAmO0VNfBOOn98u VasRHHt88XqeqQ3y3biIdfQmKzh2Tuf+c3QgJuE= X-Google-Smtp-Source: APXvYqzd6p3p3DVTSraBL22yRRae38huyu0iL1vjvVuAQScqoBkmIJOHzd1FeEsWd2NNI+W7S90PyqUsnN1fOdmm9ZE= X-Received: by 2002:a05:6402:503:: with SMTP id m3mr14208804edv.157.1570806839180; Fri, 11 Oct 2019 08:13:59 -0700 (PDT) MIME-Version: 1.0 References: <2406F2E7-CD65-4E30-A98C-C09FB52B4F2B@trowski.com> In-Reply-To: <2406F2E7-CD65-4E30-A98C-C09FB52B4F2B@trowski.com> Date: Fri, 11 Oct 2019 12:13:47 -0300 Message-ID: To: Aaron Piotrowski Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Envelope-From: Subject: Re: [PHP-DEV] exit() via exception From: marcio.web2@gmail.com (Marcio Almada) Hi! > > I don't believe atexit applies to os._exit(). In any case, I agree that > > 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 us= able > > in a webserver context, while a hypothetical pcntl_exit() would bring d= own > > the server process. As the Python docs mention, the primary use-case wo= uld > > be exiting from forked processes without going through shutdown, which = 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 we > >> 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 keeping > >> 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 existing > > catch(Throwable) catch it -- probably a no-go. > > > > 2. Making EngineShutdown not implement Throwable, which means that not = all > > "exceptions" implement the interface, which is rather odd. It still all= ows > > explicitly catching the exit. > > > > 3. Introducing a function like catch_exit(function() { ... }). This wou= ld > > still allow catching exits (for phpunit + daemon use cases), but the fa= ct > > 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 jus= t 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 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). > > EngineShutdown could be a special exception to the engine, being handled = like an exception internally, but not implement Throwable and therefore not= an exception from user-land's point-of-view. > > EngineShutdown could be added to the list of "throwables", but forbid ins= tigation 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 no= r 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