Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62309 invoked from network); 31 Aug 2014 01:33:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Aug 2014 01:33:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 108.166.43.107 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 108.166.43.107 smtp107.ord1c.emailsrvr.com Linux 2.6 Received: from [108.166.43.107] ([108.166.43.107:45415] helo=smtp107.ord1c.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/61-50403-37B72045 for ; Sat, 30 Aug 2014 21:33:45 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp6.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id 276BA803DE; Sat, 30 Aug 2014 21:33:36 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp6.relay.ord1c.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id AEB0480386; Sat, 30 Aug 2014 21:33:35 -0400 (EDT) X-Sender-Id: smalyshev@sugarcrm.com Received: from Stass-MacBook-Pro.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net [108.66.6.48]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.2.10); Sun, 31 Aug 2014 01:33:36 GMT Message-ID: <54027B6D.7060708@sugarcrm.com> Date: Sat, 30 Aug 2014 18:33:33 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: PHP Internals CC: jocelyn fournier , Dmitry Stogov Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: destructors and output_buffering From: smalyshev@sugarcrm.com (Stas Malyshev) 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? -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/