1

I was reading an article on the advantage of yield statements and iterables - a handy and useful thing where "the list is so large that merely creating it would consume all of the system's memory"

PHP also has yield statments (generators).

This would have practical implications in Wordpress - sometimes I have had to fix a site that exceeded memory limits from Wordpress' grabbing comments when thousands of spammy comments are pending in the database.

I have to wonder why Wordpress still creates a whole array of data in memory for get_posts and similar - is this something that has just never been considered, or something they absolutely have to have in array in memory for legacy code, and is impractical to rewrite?

1 Answer 1

1

Even though the recommendations have been updated to:

To run WordPress we recommend your host supports:

  • PHP version 5.6 or greater
  • MySQL version 5.6 or greater OR MariaDB version 10.0 or greater

the minimum requirements are not there yet:

WordPress server requirements for Version 3.2+:

  • PHP version 5.2.4 or greater
  • MySQL version 5.0.15 or greater or any version of MariaDB

Note that older versions of MySQL and PHP may have reached End Of Life, which means they are no longer updated and can expose your site to security vulnerabilities. For this reason, it's best to follow the recommended setup below and use the latest versions of MySQL/MariaDB and PHP that your host supports.

The reason for this is e.g.:

Why do we support older versions? We strongly recommend the latest versions of PHP and MySQL, but we understand that this isn’t right for everyone, and that sometimes hosts can be slow or hesitant to upgrade their customers since upgrades to PHP and MySQL have historically broken applications.

Hopefully the WordPress core will apply all these handy things like generators (PHP 5.5+) and namespaces (PHP 5.3+) but it will take time.

Here's e.g. a discusssion in #36335 regarding autoloading with support for PHP 5.2+.

WordPress core also runs fine on PHP 7.

But we can of course use these PHP improvements in our own projects and many plugins are not following the minimum requirements, thankfully ;-)

4
  • Aren't generators just easy iterators? "Generators provide an easy way to implement simple iterators without the overhead or complexity of implementing a class that implements the Iterator interface." - and iterator has been around since PHP5 according to documentation - php.net/manual/en/language.generators.overview.php
    – NoBugs
    Commented Jun 17, 2016 at 20:40
  • yes, but the yield statement was introduced in PHP 5.5, Maybe you mean iterator interfaces in general? I could found e.g. suggestions in ticket #20296 that was closed and #20297 that was closed as maybelater. @NoBugs
    – birgire
    Commented Jun 17, 2016 at 21:54
  • ps: It will be interesting to follow this "Requests" ticket #33055 and check out the Iterator interfaces implemented there‌​. For example the IteratorAggregate here that was mentioned in ticket #20297 @NoBugs
    – birgire
    Commented Jun 17, 2016 at 22:46
  • Where do you find those minimum requirements?
    – NoBugs
    Commented Mar 7, 2017 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.