let’s say i have a web app with 3000 books, all the info is in a DB,
and let’s say i need to recover all that info and show it on a webpage.
which one of these two approches is better in terms of memory consumption?
- Recover the info from the DB, convert that info into 3000 Book Objects and parse all of them showing the html result.
- Just recover the info from the DB and parse directly the result array into html.
probably the question is “does creating lots of objects in PHP creates memory issues?”
thanks!
yes it does, but they’re very manageable.
The fastest/most efficient way is to parse the results directly into HTML output in one giant loop, but it’s not very manageable when it comes to coding/extending
PHP with the OOP paradigm is a bit of a memory hog, but it provides some nice structure:
If you parse each entity into an object, and have the object print to the page, you can kill off each object instance. Alternatively you can gather a cluster of book instances, and parse them in chunks.