Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17773 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29412 invoked by uid 1010); 10 Aug 2005 09:45:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 29397 invoked from network); 10 Aug 2005 09:45:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2005 09:45:19 -0000 X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:33983] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 6A/B6-24081-FACC9F24 for ; Wed, 10 Aug 2005 05:45:19 -0400 Received: from [192.168.1.3] (dsl-082-083-244-080.arcor-ip.net [82.83.244.80]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id 0028A35C37B; Wed, 10 Aug 2005 12:04:25 +0200 (CEST) Date: Wed, 10 Aug 2005 11:45:22 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <124244453.20050810114522@marcus-boerger.de> To: Ron Korving Cc: internals@lists.php.net In-Reply-To: References: <21.AF.04646.20AC8F24@pb1.pair.com> <5.1.0.14.2.20050809123954.03491eb0@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: drastic memory consumption with a sequenceof exceptions From: helly@php.net (Marcus Boerger) Hello Ron, Wednesday, August 10, 2005, 8:47:25 AM, you wrote: > Okay Andi, the script in this message is as simple as it gets. I used a > syslog file to create a load of data in this case, but of course you can use > any (text) file for this. > #!/usr/bin/php5 > function process() > { > $data = file("/var/log/syslog.0"); > foreach ($data as $line) > throw new Exception("error"); What makes you think the file would be closed. Erm the array deleted? And that is your problem you are unnecessarily reading all the file into an array. Try using the same with FileObject instead, which should reduce memory usage a lot: foreach(FileObject($file) as $data) throw new Exception("error"); But of course you only did that to demonstrate the memory problem which in fact simply means that we don't do a full stack cleanup like c++ would do here (php != c++). In php we do the cleanup at script termination. That is also the reason why php is not perfectly suitable for console apps especially when it comes to daemons. best regards marcus