WordPress.org

Ready to get started?Download WordPress

Forums

Wasteful memory usage for core upgrade (2 posts)

  1. michaeltyson
    Member
    Posted 4 years ago #

    WordPress's core upgrade facility uses WP_Http in wp-includes/http.php to download the archive of the new version.

    WP_Http methods store all response data in memory, which means when they are used to download WordPress, the entire ~2.5mb archive is stored in a variable, then processed using various string-processing functions like substr, which duplicate this data further.

    On my Site5 hosted website, I'm forced to update manually as I continually run out of memory while attempting to load the update. Some googling reveals that others have the same issue, unsurprisingly.

    This could be remedied by using an alternate fetch method that writes the request body to disk. fopen or fsockopen could do this quite easily, not so much the curl method.

    Unless there's an alternative method of which I'm unaware, I propose something like the addition of a parameter in the 'args' array, the second parameter to WP_Http::request, which directs the method to write the body to disk.

    Say, a parameter called 'output', which by default is unset, indicating that the body should be placed in memory; if the value is true, it indicates that the body should be written to a temporary file. If it's a string, it indicates that the body should be written to the path given in the string. Then, on output, the 'body' element of the returned array should contain the contents of the body, if 'output' was unset, or the path to the file otherwise.
    Then, the upgrade utility should use this to write straight to the update archive.

    If/when I have time, I'll put together a patch if no one beats me to it.

  2. MichaelH
    Member
    Posted 4 years ago #

    I'm sure dd32 and the other devs at Trac would welcome a patch.

    See Reporting Bugs for info on the whole patch thingy.

Topic Closed

This topic has been closed to new replies.

About this Topic