Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94834 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30493 invoked from network); 4 Aug 2016 19:08:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2016 19:08:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=dave@mudsite.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dave+php@mudsite.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain mudsite.com designates 209.85.220.175 as permitted sender) X-PHP-List-Original-Sender: dave@mudsite.com X-Host-Fingerprint: 209.85.220.175 mail-qk0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:33650] helo=mail-qk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/6A-53111-76293A75 for ; Thu, 04 Aug 2016 15:07:20 -0400 Received: by mail-qk0-f175.google.com with SMTP id p74so240777428qka.0 for ; Thu, 04 Aug 2016 12:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mudsite-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=DcWx99Rw4+N/HysU3nnLeXZRgHhAo6/gaCbJYWsnBO0=; b=XpgdghqiEvqOnOlRajCsFNZ+eGiETvPnk/BtTO5QYnm1HyAZjZsXMOQL8jm/Y4cWqz ztXxqjjnWLGHVmDQ/fhYcgzyejwrFxrzIuYfWFYomk5m4wP+vrWKXzGiS+mvizsrx7dN OlyT+4OdfLHUIL7V/0JepsyE5FRDV2x38gOwreO8n+XVkYGb1BvRkgFDVi8aUycuN+O1 eiA9uyb9h5w4S2UboLphnPiKMWSQBae9SrZ9kc0m0+1qY9U98EnoWjM8njgCt/DK/gx1 Zrm6u5wOmiDKIS+tMQGWSiFtZbh/ndg3SKoZZCUEvLzvE5NDsiAMsKkp+Hpi6bjW0O3J OffA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=DcWx99Rw4+N/HysU3nnLeXZRgHhAo6/gaCbJYWsnBO0=; b=LjTPDUtIiEhtQBSjT+6x72Fjlg4SWHThBHsuhj9KuT8r48w2bUHRAXNj7jGvb8exNw C1BJGAbcPFe1NV25yJjlE1GtmwRXUECNeu/DFjHctQi31jYt4LmHPjhgB4Em2nejdTMC h5irJ+WxCVBKGnZWUI5GxOmSxk6IXUgutf5gJ8NmdclDIfNDPk9mKc3u1QXHI+1sy/Pn latFvuLS1kIPwpg6UsMpfVkxVj5PieNzYan07xZjTBvzSF41oVTPN4eiPuOmvEdOxFNm 8EetAdGjf8i1sU+lEILj+PwWr/4tx5qijtsE78eCkzUsZHGiMzLw3Z4bzUCtLt3WN6rg HmXw== X-Gm-Message-State: AEkoouuAr/YiY7i+AlkIaJ95MLJ09aMRIhmBvFk9JEMck61qUwEm5Rxym+hzb2sHDwef3R78lcLNVUmZZaENXw== X-Received: by 10.129.84.212 with SMTP id i203mr60325256ywb.201.1470337637328; Thu, 04 Aug 2016 12:07:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 04 Aug 2016 19:07:06 +0000 Message-ID: To: bishop@php.net, PHP internals Content-Type: multipart/alternative; boundary=001a114d6a48930548053943a849 Subject: Re: [PHP-DEV] Tracing exit() From: dave+php@mudsite.com (David Walker) --001a114d6a48930548053943a849 Content-Type: text/plain; charset=UTF-8 On Thu, Aug 4, 2016 at 12:11 PM Bishop Bettini wrote: > Hi! > > exit (and its doppelganger die) is a hard stop to the engine and there is > little telemetry provided about the circumstances (file, line, message, and > code). In source I control, exit is no big deal: I don't use exit! But in > library code, exit can be frustrating. > > register_shutdown_function + debug_backtrace doesn't help, because the > trace doesn't flow out of the shutdown function. xdebug helps to find the > exit frame, but cannot pinpoint the exact line. It seems like the engine > could help with a little extra telemetry. > > I'm wondering if the shutdown functions could access telemetry: > > register_shutdown_function(function () { > > $context = shutdown_get_context(); > > /** array ( 'exit' => array ('file' => '/path/to/Foo.php', 'line' => > 242, 'message' => "Calling exit() because...", 'code' => 0)) */ > // different SAPI may expand on this context > }); > > require 'vendor/autoload.php'; > \Vendor\Package\Class::callsExit(); > ?> > > Or, alternatively, I wonder if a method to convert an exit to an exception > would be better: > > echo ini_get('zend.exit_exception'); // "1" > > try { > require 'vendor/autoload.php'; > \Vendor\Package\Class::callsExit(); > } catch (\ExitException $ex) { // extends \RuntimeException > echo 'Stop that!'; > } > ?> > > (In all these examples, "callsExit" is vendor code that performs an > undesirable exit();) > > This latter approach feels more modern, at least from a user perspective, > but it has the side effect of making exit recoverable. IMO, that's a good > thing, because the conditions under which libraries exit may merely be > exceptional for consuming applications. > > However, I'm uncertain of an "exit exception" implementation. Perhaps when > INI enabled, zend_compile_exit could rewrite to emit ZEND_THROW with a > synthetic node. Or all the ZEND_EXIT could be updated to throw instead of > bailout. Don't know. > > TL;DR: Engine support for tracing/trapping/debugging exit helps developers > find and avoid hard exits in dependent code they don't control. Thoughts on > proceeding with an RFC? > > bishop > I'd be supportive of this, as you define it. However, since you're asking for comments, I'd really be supportive of some means in which telemetry of a call could be gathered for more than just exit & die. Rarely, but not never, we have a new-ish developer who's just been given perms to commit/update production and accidentally pushes code with print-to-screen debugging. It would be amazing if this concept could be extended out to general userland functions/functions/constructs. To be able to see what lines a specific call is being made to help track down where offending code might be happening. -- Dave --001a114d6a48930548053943a849--