Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52444 invoked by uid 1010); 24 Apr 2007 09:23:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52429 invoked from network); 24 Apr 2007 09:23:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2007 09:23:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.sklar@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.sklar@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.132.247 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: david.sklar@gmail.com X-Host-Fingerprint: 209.85.132.247 an-out-0708.google.com Received: from [209.85.132.247] ([209.85.132.247:39925] helo=an-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/AC-21560-59CCD264 for ; Tue, 24 Apr 2007 05:23:33 -0400 Received: by an-out-0708.google.com with SMTP id c28so2521754ana for ; Tue, 24 Apr 2007 02:23:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oYxvATqVQKUKICzSNaBkNS3zB/JOCxPMT04MiSyP/sAwkT8F3rf/bEh5Sekcfkf1OnRYw97rsIA305i8e1IHfovlO9QprcnTivIYsh1Xqg8WL5qWB8M0N9/Xf3V7wqngMiby60DeWmUY8y33oS23NUBlb/lR9VoBLUCbTio1Ck8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=B6xFRCSJQ688v+16Ohvy1RIRb4TItYDyGBqpSOM5P4mkS9wYESd3CArm+q3iJxGT+cKJ0yS/k8swwPpqygKi5KNvKT/lkQjZYEAVqk6rj2Jg5hgNCw+zbX7aEjDBa3clYxjMo0GZt4u7piqZQlqFeyxmVUNgJ4wCRvep+wVIKws= Received: by 10.100.96.9 with SMTP id t9mr4385690anb.1177406610044; Tue, 24 Apr 2007 02:23:30 -0700 (PDT) Received: by 10.100.168.17 with HTTP; Tue, 24 Apr 2007 02:23:29 -0700 (PDT) Message-ID: <7cea347c0704240223s5623ddb3yb8d2003d8c417370@mail.gmail.com> Date: Tue, 24 Apr 2007 11:23:29 +0200 To: "internals@lists.php.net" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Subject: Re: [PHP-DEV] require_once From: david.sklar@gmail.com ("David Sklar") require_once verifies (via stat()) each path component in the path being loaded so that it can canonicalize it to check it against the canonicalized list of already-required files. Run your script below under strace and you will see all of those stats gumming up the works. Note also that if you want maximum performance here, pass full paths, not relative paths, to include/require to avoid any include_path overhead. David On 4/24/07, dletz@blog.de wrote: > Hello everyone, > > when testing speed of includes and requires i found that "require_once" > seems to be very slow in comparison to "require". Even worse > "require_once" seems to be slower than a php function "myrequire_once". > This is true not only for cli but also when using apc or eAccelerator. > Does anyone has an explanation for this? > > Testcode: > $start_time = microtime(true); > > function myrequire_once($file) > { > static $loaded = array(); > if (!array_key_exists($file, $loaded)) > { > $loaded[$file] = 1; > require $file; > } > } > > for ($i=0;$i<1000;$i++) { > require_once('manyClasses/'.$i.'.class.php'); > //myrequire_once('manyClasses/'.$i.'.class.php'); > } > > $execution_time = microtime(true) - $start_time; > echo number_format($execution_time,4)."\n"; > ?> > > I first generated the classes in manyClasses with this generation code > (you have to create the directory manyClasses first): > > $template = ' class A%s > { > private $B%s = "%s"; > function C%s($arg1, $arg2) > { > if (rand() > 1000) > return $arg1 + $arg2; > else > return 0; > } > }; > ?>'; > > for($i=0; $i< 1000; $i++) > { > $rand = rand(); > $file = sprintf($template, md5($rand), md5($rand+1), md5($rand+2), > md5($rand+3)); > file_put_contents('manyClasses/'.$i.'.class.php', $file); > } > ?> > > > Faithfully > Dominic Letz > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >