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

This comment was marked as resolved.

@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

This comment was marked as resolved.

@swissspidy
Copy link
Member

Related: #6180

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

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