PHP some $_POST values missing but are present in php://input
When debugging a large HTML form submission where specific fields vanish from $_POST despite appearing in the raw request body, the issue rarely lies in browser transmission or Apache configuration alone. It usually stems from how PHP parses multipart requests and handles memory during that parsing phase.
The discrepancy you observed between the raw data retrieved via file_get_contents('php://input') and the contents of $_POST is a classic symptom of incomplete request body parsing. While php://input streams the raw bytes exactly as they arrived from the client, $_POST is a superglobal populated only after PHP successfully parses the multipart form data. If the parsing process encounters an error or hits a hard limit before completion, $_POST will be truncated or partially empty, even though the raw stream remains intact.
In your specific case, involving arrays like t_dodparam[198], the absence of certain keys suggests that PHP stopped processing the form fields mid-stream. This often happens when the request body exceeds the configured post_max_size. When a POST payload surpasses this limit, PHP does not necessarily reject the entire request immediately with a 500 error; instead, it may truncate the parsing logic. Consequently, variables processed before the threshold are populated in $_POST, while subsequent variables are ignored because the parser considers the request "too large" for safe processing under standard settings.
Adjusting post_max_size and memory_limit is a logical first step, but simply setting these values to 256M or 150M does not guarantee success if the underlying parsing mechanism fails due to memory exhaustion during the multipart splitting process. The documentation correctly notes that if a request exceeds post_max_size, $_POST should theoretically be empty or incomplete. However, in practice, you often see a mix of parsed and unparsed data, which makes debugging difficult without inspecting the raw stream.
To resolve this, ensure your configuration file (php.ini) is set to allow sufficiently large POST bodies:
post_max_size = 160M
upload_max_filesize = 150M
memory_limit = 256M
Note that post_max_size must always be smaller than upload_max_filesize. If you are running multiple applications on a single server, these settings are global; increasing them for one script might impact others if they share the same PHP instance.
If your application is built with Laravel or a modern framework, relying on raw $_POST inspection for debugging large forms is not recommended. Frameworks often provide better mechanisms to handle large payloads, such as streaming request bodies directly from the input stream rather than parsing them entirely into memory first. For example, in Laravel, you can access the raw input stream using $request->getContent(), which avoids populating the superglobal arrays until necessary, allowing you to inspect specific fields without triggering a full parse failure.
Additionally, check for any custom .htaccess rules or load balancer configurations (like Nginx or HAProxy) that might be truncating the request body before it reaches PHP. Sometimes, a proxy server will drop large payloads silently if its own buffer limits are lower than your PHP settings. Ensure that client_max_body_size in Nginx or equivalent settings in Apache match or exceed your PHP configuration.
Finally, consider whether the form submission method is optimal for such large datasets. For extremely large forms, switching to multipart/form-data with chunked encoding or using a temporary file upload strategy might be more robust than relying on $_POST arrays entirely. This approach keeps memory usage predictable and avoids the pitfalls of partial parsing that leave you with missing keys like t_dodparam2[198].