Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76982 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88430 invoked from network); 31 Aug 2014 09:44:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Aug 2014 09:44:45 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.178 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.178 mail-lb0-f178.google.com Received: from [209.85.217.178] ([209.85.217.178:45101] helo=mail-lb0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/00-22700-B8EE2045 for ; Sun, 31 Aug 2014 05:44:44 -0400 Received: by mail-lb0-f178.google.com with SMTP id v6so4585903lbi.9 for ; Sun, 31 Aug 2014 02:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=jGP7bSvvU5+pTfCWygkpFuJPYixv9c7pQ6lTakn4rPs=; b=v/6hASf4B3aNWZrcSbEyokfOWVADEscRswN/bDhE7AwZO3QVm+UTwYN82MPC810Q1q /gUAmEzZIlO0/h1R36K5W+CfLcWc9e6l8m3F5QKZ1cV7rpAWzghbe/UzsmtHjEBrRo5b EVpml54PP3jSqK2u/WvjdCbIiiHRPjcnqdiLPadlJasjT029vq9NjQDbJrPbX22Od+T4 zed0eWm65DDGhw9THJ6QwhSlvzoUK/YnBD/QhGatTPZBtSYLE9OJscMheySd7n6psbaY F40Jkfc/rG2/xx2gPZir9yDpEnxk129pIvLb9MRzXOVn2nM6d9cvdOvPeR+ue/vEAJaN W8pQ== MIME-Version: 1.0 X-Received: by 10.152.36.73 with SMTP id o9mr1282367laj.88.1409478280654; Sun, 31 Aug 2014 02:44:40 -0700 (PDT) Received: by 10.25.154.209 with HTTP; Sun, 31 Aug 2014 02:44:40 -0700 (PDT) In-Reply-To: <54027B6D.7060708@sugarcrm.com> References: <54027B6D.7060708@sugarcrm.com> Date: Sun, 31 Aug 2014 11:44:40 +0200 Message-ID: To: Stas Malyshev Cc: PHP Internals , jocelyn fournier , Dmitry Stogov Content-Type: multipart/alternative; boundary=089e0160adf83cb88c0501e9bc25 Subject: Re: [PHP-DEV] destructors and output_buffering From: nikita.ppv@gmail.com (Nikita Popov) --089e0160adf83cb88c0501e9bc25 Content-Type: text/plain; charset=UTF-8 On Sun, Aug 31, 2014 at 3:33 AM, Stas Malyshev wrote: > Hi! > > I was looking at bug https://bugs.php.net/bug.php?id=67644 and it looks > like we have a bit of a problem with output buffering and dtors on > shutdown. Basically, right now our code looks like this: > > /* 2. Call all possible __destruct() functions */ > zend_try { > zend_call_destructors(TSRMLS_C); > } zend_end_try(); > > /* 3. Flush all output buffers */ > zend_try { > > // And here we go flushing output buffers > > Now, since ob functions can have userland handlers, these handlers can > create new objects. And these objects will not benefit from orderly dtor > round that zend_call_destructors(TSRMLS_C) is providing - instead their > dtors will be called from zend_objects_store_free_object_storage() and > by then their environment may already be ruined and their dtors can not > run properly. > > OTOH, moving __destruct after output buffers may not be good either, as > dtors may output something. > > The problem seems to be resolved if I either duplicate > zend_call_destructors(TSRMLS_C); after the output buffers flushing or put > zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC); > there. > > Of course, the second solution has the downside of not calling the dtors > of objects that were created while flushing ob buffers. The > zend_call_destructors would work but since output buffering is supposed > to be shut down by then, I wonder if it won't also have bad consequences > if these dtors do something with output buffering. > > I'm leaning towards the second solution - if you create the objects so > late on shutdown stage, you shouldn't really expect them to be destroyed > normally, otherwise the cycle would never end. However, we could > consider the first option too. Any thoughts? > Instead of iterating through all objects and setting a flag, can't we set a global flag that object dtors are not called after this point? This both solves the issue of new objects being created after the fact and makes shutdown less expensive. Nikita --089e0160adf83cb88c0501e9bc25--