Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61856 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20169 invoked from network); 28 Jul 2012 08:38:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2012 08:38:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.216.170 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.216.170 mail-qc0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:36604] helo=mail-qc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/25-23870-125A3105 for ; Sat, 28 Jul 2012 04:38:58 -0400 Received: by qcmt36 with SMTP id t36so2644353qcm.29 for ; Sat, 28 Jul 2012 01:38:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=eEWOF+WoYrZYObF8Rxkd7HJbDwA/5hDM0oRJndqHoZE=; b=jeYCgUkvs9BBKqSepINXuDKw/sKTb4HZ9g8xoDLtQqpYrnG06pBtE+UiEk0ylQMJcF GFSWP6QNJolMVpXZ546SXQAliQWXth5OvIFpPm5krz8Qjq2zclqzOZeHc7C33Ps4gCey tvenkbmaLs0KHkYep9UzkrHf6qm8SXG9+yRHJBsn3pbloiNgBganoVyv0Gqwv7B/v14j Aq7L1wM69wdD80gAALe8huG5KDq8mbQnu/FZbGJ2HMpK+pSBxARy4JAmTtoZ4OEAwdwE bPo6QeYMqbQNV761XwFERWLgbrqDGRpUMN2CW7UK4JbUaNLEcOMh1Dh65i3z2fNqtvn+ jkQw== Received: by 10.224.78.198 with SMTP id m6mr12942301qak.30.1343464735023; Sat, 28 Jul 2012 01:38:55 -0700 (PDT) Received: from [172.16.26.30] ([38.106.64.245]) by mx.google.com with ESMTPS id g10sm3537027qae.12.2012.07.28.01.38.53 (version=SSLv3 cipher=OTHER); Sat, 28 Jul 2012 01:38:54 -0700 (PDT) Message-ID: <5013A51B.4020008@lerdorf.com> Date: Sat, 28 Jul 2012 01:38:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Lester Caine CC: PHP internals References: <5010138D.5050804@ajf.me> <501015B9.6050704@ajf.me> <501085FE.7070406@lerdorf.com> <501382B3.2090702@lerdorf.com> <50138DD1.1090009@lsces.co.uk> <5013903A.6030009@lerdorf.com> <501396A9.9080400@lsces.co.uk> In-Reply-To: <501396A9.9080400@lsces.co.uk> X-Enigmail-Version: 1.5a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmMtBYSt1kNW68Cwje7BU/9UooWA1XIInLh7/3MMIdxSD588s3e4PGfDqK1HNim+XzXrJb+ Subject: Re: [PHP-DEV] Re: Generators in PHP From: rasmus@lerdorf.com (Rasmus Lerdorf) On 07/28/2012 12:37 AM, Lester Caine wrote: > Rasmus Lerdorf wrote: >>>> I don't think this generator question is any different. We need to >>>> >>explain generators in the simplest way possible. The simplest way to >>>> >>explain generators is to not even worry about them being >>>> generators at >>>> >>all. Simply say that functions can now return arrays one element at a >>>> >>time using the new yield keyword. That's all. >>> > >>> >It's this 'concept' that I am having trouble seeing in the general >>> >process that is required using PHP to generate web pages. At the end of >>> >the day I have to generate the finished page or sub-page so I need all >>> >the results anyway. >> Sure, but that doesn't mean it has to all be in memory at the same time. >> You can read lines from a large file line-by-line, process that line and >> output the result before you move onto the next line. > > Exactly ... when uploading the NLPG csv files I process them line at a > time and store to the database. I always have ... which is why I don't > recognise the initial 'complaint' that justified adding this. These > files can be 100Mb+ so there is no way one would process them by reading > the whole lot in as the 'example' gave. You just call the function that > processes the particular type of line which is based on the first two > characters ... after reading the line. Great, so you recognize the use-case. Now you just need to get to the next step which is that instead of having the iterating part call out to the processors for each iteration sometimes it is convenient to have it be processor-centric and have the processors be able to call the iterator to get the next element without duplicating that code in every processor. -Rasmus