Decoding the "Unexpected Response" Error in WordPress Media Uploads
When you encounter the message "Unexpected response from the server. The file may have been uploaded successfully," it is rarely a vague indication of a broken server. In practice, this error usually signals a specific breakdown in the communication flow between your web server (Apache or Nginx) and your PHP process (PHP-FPM). The client-side script initiates a multipart upload request, but before PHP can finalize the move_uploaded_file operation and return a definitive success status code, the connection is severed or the response is malformed.
A common culprit in this scenario is the mismatch between configuration limits that appear generous on paper but fail under load due to memory exhaustion or timeout constraints. In your specific case, you have configured php.ini with upload_max_filesize = 50G, post_max_size = 50G, and memory_limit = 1G. While these settings are theoretically sufficient for a 200MB MP4 file, they do not account for the additional memory required to parse the request body or the overhead of the PHP-FPM pool.
The fact that a 27MB file uploads without issue while a 200MB file triggers this error suggests the bottleneck is likely not the raw upload limit itself, but rather how the server handles large payloads during the processing phase. When PHP attempts to process a large file, it needs sufficient RAM to hold the request data before writing it to disk. If memory_limit is hit during the parsing or initial validation stage (which happens before the actual file move), PHP may abort silently or return a 500 error, which WordPress then intercepts as an "unexpected response."
Verifying Memory Limits in Practice
Setting memory_limit = 1G in php.ini is only half the battle. You must ensure this setting applies to the specific PHP-FPM pool you are using. If your production server runs on Ubuntu with Apache and PHP-FPM, modifying the global php.ini might not affect your active workers if they are defined in a separate .conf.d file or via an override configuration.
Check your actual memory usage during a failed upload attempt. You can do this by tailing the error log:
sudo tail -f /var/log/php-fpm/error.log
# Or for Apache:
sudo tail -f /var/log/apache2/error.log
Look for entries mentioning "Out of memory," "Fatal error," or "Allowed memory size exhausted." If you see these errors, increasing the memory_limit is mandatory. However, simply raising it in one file isn't enough; you must ensure the directive is present in the configuration file that your specific PHP-FPM process actually loads.
The Role of Timeout Settings
Another frequent cause for "unexpected response" errors with large files involves execution timeouts. Even if memory is available, PHP might take too long to process a 200MB binary file depending on server load. If the request hangs and the web server (Apache or Nginx) kills the connection due to request_timeout settings before PHP finishes, you get exactly the error you are seeing.
In your Apache configuration (/etc/apache2/sites-available/000-default.conf), ensure that LimitRequestBody is not set to a value lower than 50G, as this directive can override php.ini settings for file uploads specifically. Additionally, verify that your PHP-FPM pool has sufficient time to execute:
<Directory /var/www/html>
LimitRequestBody 52428800000 # Allow ~50GB in bytes
</Directory>
And ensure the PHP-FPM configuration includes a reasonable request_terminate_timeout if you are using dynamic pools, though usually, this is less critical than memory.
Why Restarting Didn't Help
You mentioned restarting PHP-FPM and Apache2 without success. This is expected behavior if the root cause lies in runtime memory exhaustion or misconfigured pool definitions. A restart clears the process memory but does not change the hard limits defined in the configuration files. If your php.ini has memory_limit = 1G but your php-fpm.d/www.conf overrides it to something lower, restarting will just cycle back to the stricter limit.
To truly resolve this, you need to audit every layer of the stack:
- Web Server: Check Apache/Nginx
LimitRequestBody. - PHP Core: Verify
upload_max_filesize,post_max_size, andmemory_limitin the effective config (usephpinfo()orphp -ito confirm which file is loaded). - System Resources: Ensure your VPS or server instance actually has enough physical RAM to handle a spike in memory usage during a large upload. If you are running on a shared host with strict resource capping, even generous config changes might be ignored by the hosting provider's kernel limits.
If you are building a similar application using Laravel, this specific error pattern often appears when php.ini settings are overridden by framework-level caching or when the queue worker runs out of memory. In such cases, ensuring your environment variables respect these limits and that you are not hitting container resource caps (like Docker --memory) is crucial.
Conclusion on Troubleshooting Steps
Before assuming the file was uploaded successfully, always check the filesystem where WordPress stores uploads (/wp-content/uploads). If the file exists there with the correct size, the upload worked despite the error message, and you can safely ignore it. However, if the file is missing or partially written, the "unexpected response" indicates a hard failure in the write process, likely due to memory pressure or timeout constraints that must be addressed by tuning your server's configuration files rather than just restarting services.
