Skip to content

Remove forced infinite memory_limit#6207

Open
Copilot wants to merge 2 commits intomainfrom
copilot/remove-infinite-memory-limit
Open

Remove forced infinite memory_limit#6207
Copilot wants to merge 2 commits intomainfrom
copilot/remove-infinite-memory-limit

Conversation

Copy link
Contributor

Copilot AI commented Jan 25, 2026

WP-CLI currently forces memory_limit to -1 (unlimited) at runtime to work around WordPress core issue #14889, which was resolved years ago. This prevents server administrators from configuring appropriate memory limits and blocks graceful error handling when limits are exceeded.

Changes

  • Removed ini_set('memory_limit', -1) from Runner::load_wordpress()
  • WP-CLI now respects the PHP memory_limit configuration (including -1 if explicitly set)
  • Existing test validates operation with memory_limit=256M and ini_set disabled

Impact

Server administrators can now:

  • Configure memory limits appropriate for their environment
  • Get proper error handling and shutdown hooks when limits are reached
  • Still set -1 explicitly if unlimited memory is desired

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php 0 -j ACCEPT (dns block)
  • nosuchhost_asdf_asdf_asdf.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php 0 -j ACCEPT (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Currently forcing an infinite php memory_limit</issue_title>
<issue_description>## Bug Report

The Problem

WP CLI overrides server configurations and sets the memory limit to -1 during runtime, seen here:

wp-cli/php/WP_CLI/Runner.php

Lines 1276 to 1278 in c3bd5bd

// Fix memory limit. See https://core.trac.wordpress.org/ticket/14889
// phpcs:ignore WordPress.PHP.IniSet.memory_limit_Blacklisted -- This is perfectly fine for CLI usage.
ini_set( 'memory_limit', -1 );

The mentioned trac ticket has been resolved for a while now :), and servers can configure -1 if they desire to.

Recommended Solution

I believe it would be best for WP CLI to remove itself from making this decision at run time. Setting proper memory limits allows for more graceful handling of requests/commands that do end up exceeding the limit. Otherwise, it can be left up to a lower-level process to kill off the request - leaving behind a less-than-graceful result (shutdown functions can't attempt to run, etc).

If it's agreed to remove this from the package, then I would recommend doing this in a major release with ample notice so others can decide on if they need to increase this value or not before upgrading.</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber @schlessera This seems like a good candidate for a 3.0.0 too.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove infinite memory limit imposed by WP CLI Remove forced infinite memory_limit Jan 25, 2026
Copilot AI requested a review from swissspidy January 25, 2026 17:10
@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review February 4, 2026 02:02
@swissspidy swissspidy requested a review from a team as a code owner February 4, 2026 02:02
Copilot AI review requested due to automatic review settings February 4, 2026 02:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes WP-CLI's forced unlimited PHP memory limit setting that was originally implemented to work around WordPress core issue #14889 (resolved years ago). The change allows server administrators to configure appropriate memory limits for their environments while maintaining the option to set unlimited memory explicitly if desired.

Changes:

  • Removed ini_set('memory_limit', -1) from Runner::load_wordpress() method
  • Eliminated reference to WordPress Trac ticket #14889 in code comments
  • WP-CLI now respects the PHP memory_limit configuration set by administrators

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Currently forcing an infinite php memory_limit

2 participants