PHP, when to use iterators, how to buffer results?

Posted by Jon L. on Programmers See other posts from Programmers or by Jon L.
Published on 2012-03-21T20:07:32Z Indexed on 2012/03/21 23:39 UTC
Read the original article Hit count: 249

Filed under:
|
|
  1. When is it best to use Iterators in PHP, and how can they be implemented to best avoid loading all objects into memory simultaneously?
  2. Do any constructs exist in PHP so that we can queue up results of an operation for use with an Iterator, while again avoiding loading all objects into memory simultaneously?
    1. An example would be a curl HTTP request against a REST server
  3. In the case of an HTTP request that returns all results at once (a la curl), would we be better off to go with streaming results, and if so, are there any limitations or pitfalls to be aware of?
    1. If using streaming, is it better to replace curl with a PHP native stream/socket?

My intention is to implement Iterators for a REST client, and separately a document ORM that I'm maintaining, but only if I can do so while gaining benefits from reduced memory usage, increased performance, etc. Thanks in advance for any responses :-)

© Programmers or respective owner

Related posts about php

Related posts about sockets