Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46035 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65829 invoked from network); 12 Nov 2009 19:55:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Nov 2009 19:55:07 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.227 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:47256] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/0B-08668-A186CFA4 for ; Thu, 12 Nov 2009 14:55:07 -0500 Received: by fxm27 with SMTP id 27so2706856fxm.23 for ; Thu, 12 Nov 2009 11:55:03 -0800 (PST) Received: by 10.204.6.24 with SMTP id 24mr3757910bkx.25.1258055699447; Thu, 12 Nov 2009 11:54:59 -0800 (PST) Received: from ?192.168.200.22? (c-69-181-146-64.hsd1.ca.comcast.net [69.181.146.64]) by mx.google.com with ESMTPS id 28sm601841fkx.29.2009.11.12.11.54.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 12 Nov 2009 11:54:58 -0800 (PST) Message-ID: <4AFC680F.7050400@lerdorf.com> Date: Thu, 12 Nov 2009 11:54:55 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Basant Kukreja CC: internals@lists.php.net References: <20091112185555.GB4294@lbasantk3.red.iplanet.com> In-Reply-To: <20091112185555.GB4294@lbasantk3.red.iplanet.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] open/close calls of include_once/require_once files. From: rasmus@lerdorf.com (Rasmus Lerdorf) A couple of notes. You make it sound like this happens on all includes. It is only include_once/require_once that have this problem. Regular include/require do not. This has been addressed in APC by overriding the opcode and providing our own opcode handler for this case. See http://svn.php.net/viewvc/pecl/apc/trunk/apc_zend.c?view=markup&pathrev=289331 line 86. Having said that, it would be preferable, of course, if we didn't need to swap out that code in APC but I am not sure your solution for solving this only for absolute path includes is the right way to go here. -Rasmus Basant Kukreja wrote: > Hi, > When php script includes a script, php engine compiles the included file. > When opcode caching extensions e.g apc are used, re-compilation is avoided by > apc. But there is a performance problem here. Since php code uses > zend_stream_open to open the included file, open/close system call is still > there. When used with APC, open/close doesn't do any good for file-system based > files. It only provides the realpath of the opened file. In php 5.3, > zend_resolve_path already provides the realpath of the file being opened so we > can avoid an open/close calls for file to be included if file is an absolute > path. > > Current php 5.3 implementation for include_once/require_once (pseudo code) > > a) call zend_resolve_path. It will provide the realpath. Symlinks are taken > care of by zend_resolve_path. > b) Check if file is already included. If yes, do nothing else go to step (c) > c) Call zend_stream_open and get the included_file realpath. > d) Invoke zend_compile_file and do the rest. > > Now zend_stream_open invokes the open/close calls to the including files which > is redundant when caches are used. > > Here is the suggested performance fix : > a) Same as previous > b) Same as previous > c) If resolved_path is an absolute path then do step c.1 else do c.2 > c.1) Prepare a file_handle and directly invoke zend_compile_file > c.2 Call zend_stream_open and get the included_file realpath. > b) Same as previous > > --------------------------------------------------- > > Few notes : > * Performance improvements using this patch = ~1.5% in an e-commerce workload. > * Testing : I ran the php 5.3 test suite and didn't find any regression. > * If files which are included are not absolute paths then they will follow > the same zend_stream_path route. > * Tested with symlinks and found the behaviour is expected (no change). > > I have attached the patch for review comments. > > Regards, > Basant. > > Note: I previously did this work for php 5.2 but bug remains still open. 5.3 > implementation is relatively straight forward. Here is the reference to 5.2 bug > : http://bugs.php.net/bug.php?id=47660&thanks=2 > > >