{"id":251,"date":"2020-07-24T00:15:49","date_gmt":"2020-07-23T22:15:49","guid":{"rendered":"https:\/\/www.kopf.com.br\/kaplof\/?p=251"},"modified":"2020-07-24T00:20:24","modified_gmt":"2020-07-23T22:20:24","slug":"how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0","status":"publish","type":"post","link":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/","title":{"rendered":"How to fix &#8211; PHP Warning:  Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0"},"content":{"rendered":"\n<p>So you have a PHP website and out of sudden, when users send POST requests or upload files, you get the error message:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0<\/pre>\n\n\n\n<p>Well there are different reasons why you may get such an error. This articles goes through the common causes and solutions for this error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the error<\/h2>\n\n\n\n<p>The error says that PHP was unable to buffer the post data, but it doesn&#8217;t really say why. <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/php\/php-src\/blob\/91fbd12d5736b3cc9fc6bc2545e877dd65be1f6c\/main\/SAPI.c#L272\" target=\"_blank\">Looking at the code<\/a>, we see that the actual cause of the error is that the number of bytes written to the buffer is different to the number of bytes read from the input. Unfortunately if the logs don&#8217;t tell us anything additional, it is just outputting the symptom not the cause.<\/p>\n\n\n\n<p>To make things worse, it is a warning a not a real error, meaning that your code will continue the flow on a corrupted state.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Possible causes to the error and how to fix them<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Permissions on the temporary folder<\/h3>\n\n\n\n<p>The most likely cause for this error is that the user running the PHP process doesn&#8217;t have the right to save a file in the temporary folder. <\/p>\n\n\n\n<p>Usually if the problem is in the temporary folder, you should also see the <a href=\"https:\/\/stackoverflow.com\/questions\/18395163\/warning-file-upload-error-unable-to-create-a-temporary-file-in-unknown-on-lin\" target=\"_blank\" rel=\"noreferrer noopener\">warning message<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Warning: File upload error - unable to create a temporary file in Unknown on line 0<\/pre>\n\n\n\n<p>The temporary folder for file uploads is defined by the php.ini directive <a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/manual\/en\/ini.core.php#ini.upload-tmp-dir\" target=\"_blank\">upload_tmp_dir<\/a>. When empty it uses the system default temporary directory (in Linux usually \/tmp). <\/p>\n\n\n\n<p>You can type this in the command line to find out what is the temporary dir.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php -r 'echo ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();'<\/pre>\n\n\n\n<p>Once you know the folder you can change the permissions with chmod (in the below example for the \/tmp folder)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod -R 777 \/tmp<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Out of disk space or quota<\/h3>\n\n\n\n<p>Similar to the error above, if PHP is receiving big post requests and there is not enough capacity for the server or the user to save a temporary file, you should get the same warning as above. To check the available space in the temporary folder you can try the command diskfree (df). The example below assumes that the temporary folder is \/tmp<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ df \/tmp\nFilesystem 1K-blocks Used Available Use% Mounted on\n\/dev\/sda3 4062912 76344 3760472 2% \/tmp<\/pre>\n\n\n\n<p>If you are out of disk space, well&#8230; get more space \ud83d\ude42<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Out of memory<\/h3>\n\n\n\n<p>If your process runs out of memory, you might get the same error. In this case, an out of memory message should precede the POST warning.<\/p>\n\n\n\n<p>You have to check if the server (or virtual machine) is running out of memory or if the PHP reached its memory limit. PHP memory limits are configured by the directive <a href=\"http:\/\/php.net\/memory_limit\"><code>memory_limit<\/code><\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Upload file limits<\/h3>\n\n\n\n<p>PHP has several directives to control how big files can be and how many files an user can upload. If you hit any of these limits you might receive this error messages. You can adjust the upload limits through the php.ini directives:<\/p>\n\n\n\n<ul><li><a href=\"http:\/\/php.net\/post_max_size\"><code>post_max_size<\/code><\/a><\/li><li><a href=\"http:\/\/php.net\/max_input_time\"><code>max_input_time<\/code><\/a><\/li><li><a href=\"http:\/\/php.net\/max_input_nesting_level\"><code>max_input_nesting_level<\/code><\/a><\/li><li><a href=\"http:\/\/php.net\/max_input_vars\"><code>max_input_vars<\/code><\/a><\/li><li><a href=\"http:\/\/php.net\/upload_max_filesize\"><code>upload_max_filesize<\/code><\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Other possible errors<\/h3>\n\n\n\n<p>Some other documented cases:<\/p>\n\n\n\n<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/wordpress.org\/support\/topic\/error-on-updating-some-pages-and-posts\/\" target=\"_blank\">A server reboot solved the problem<\/a>, because of a pending update.<\/li><li>A <a rel=\"noreferrer noopener\" href=\"https:\/\/forums.cpanel.net\/threads\/big-phpxxxxxx-files-in-home-user-cagefs-tmp.609659\/\" target=\"_blank\">wordpress plugin<\/a> was writing big files, filling up the tmp folder.<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you have a PHP website and out of sudden, when users send POST requests or upload files, you get the error message: PHP Warning: Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0 Well there are different reasons why you may get such an error. This articles goes through [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to fix - PHP Warning: Unknown: POST data can&#039;t be buffered; all data discarded in Unknown on line 0 - Kaplof<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to fix - PHP Warning: Unknown: POST data can&#039;t be buffered; all data discarded in Unknown on line 0 - Kaplof\" \/>\n<meta property=\"og:description\" content=\"So you have a PHP website and out of sudden, when users send POST requests or upload files, you get the error message: PHP Warning: Unknown: POST data can&#039;t be buffered; all data discarded in Unknown on line 0 Well there are different reasons why you may get such an error. This articles goes through [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\" \/>\n<meta property=\"og:site_name\" content=\"Kaplof\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-23T22:15:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-23T22:20:24+00:00\" \/>\n<meta name=\"author\" content=\"Bruno Marotta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bruno Marotta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\"},\"author\":{\"name\":\"Bruno Marotta\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/a096a6de30951e12938c6a800eeaa891\"},\"headline\":\"How to fix &#8211; PHP Warning: Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0\",\"datePublished\":\"2020-07-23T22:15:49+00:00\",\"dateModified\":\"2020-07-23T22:20:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\"},\"wordCount\":507,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#organization\"},\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\",\"url\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\",\"name\":\"How to fix - PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0 - Kaplof\",\"isPartOf\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#website\"},\"datePublished\":\"2020-07-23T22:15:49+00:00\",\"dateModified\":\"2020-07-23T22:20:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.kopf.com.br\/kaplof\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to fix &#8211; PHP Warning: Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#website\",\"url\":\"https:\/\/www.kopf.com.br\/kaplof\/\",\"name\":\"Kaplof\",\"description\":\"Sharing problems and solutions for software development\",\"publisher\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.kopf.com.br\/kaplof\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#organization\",\"name\":\"Kopf\",\"url\":\"https:\/\/www.kopf.com.br\/kaplof\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i0.wp.com\/www.kopf.com.br\/kaplof\/wp-content\/uploads\/2015\/04\/Logo-grande.png?fit=78%2C76&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.kopf.com.br\/kaplof\/wp-content\/uploads\/2015\/04\/Logo-grande.png?fit=78%2C76&ssl=1\",\"width\":78,\"height\":76,\"caption\":\"Kopf\"},\"image\":{\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/a096a6de30951e12938c6a800eeaa891\",\"name\":\"Bruno Marotta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8e15f82b4b9672c32c601286a40eb46f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8e15f82b4b9672c32c601286a40eb46f?s=96&d=mm&r=g\",\"caption\":\"Bruno Marotta\"},\"url\":\"https:\/\/www.kopf.com.br\/kaplof\/author\/bmarotta\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to fix - PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0 - Kaplof","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/","og_locale":"en_US","og_type":"article","og_title":"How to fix - PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0 - Kaplof","og_description":"So you have a PHP website and out of sudden, when users send POST requests or upload files, you get the error message: PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0 Well there are different reasons why you may get such an error. This articles goes through [&hellip;]","og_url":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/","og_site_name":"Kaplof","article_published_time":"2020-07-23T22:15:49+00:00","article_modified_time":"2020-07-23T22:20:24+00:00","author":"Bruno Marotta","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bruno Marotta","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#article","isPartOf":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/"},"author":{"name":"Bruno Marotta","@id":"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/a096a6de30951e12938c6a800eeaa891"},"headline":"How to fix &#8211; PHP Warning: Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0","datePublished":"2020-07-23T22:15:49+00:00","dateModified":"2020-07-23T22:20:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/"},"wordCount":507,"commentCount":0,"publisher":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/#organization"},"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/","url":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/","name":"How to fix - PHP Warning: Unknown: POST data can't be buffered; all data discarded in Unknown on line 0 - Kaplof","isPartOf":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/#website"},"datePublished":"2020-07-23T22:15:49+00:00","dateModified":"2020-07-23T22:20:24+00:00","breadcrumb":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.kopf.com.br\/kaplof\/how-to-fix-php-warning-unknown-post-data-cant-be-buffered-all-data-discarded-in-unknown-on-line-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kopf.com.br\/kaplof\/"},{"@type":"ListItem","position":2,"name":"How to fix &#8211; PHP Warning: Unknown: POST data can&#8217;t be buffered; all data discarded in Unknown on line 0"}]},{"@type":"WebSite","@id":"https:\/\/www.kopf.com.br\/kaplof\/#website","url":"https:\/\/www.kopf.com.br\/kaplof\/","name":"Kaplof","description":"Sharing problems and solutions for software development","publisher":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kopf.com.br\/kaplof\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.kopf.com.br\/kaplof\/#organization","name":"Kopf","url":"https:\/\/www.kopf.com.br\/kaplof\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/www.kopf.com.br\/kaplof\/wp-content\/uploads\/2015\/04\/Logo-grande.png?fit=78%2C76&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.kopf.com.br\/kaplof\/wp-content\/uploads\/2015\/04\/Logo-grande.png?fit=78%2C76&ssl=1","width":78,"height":76,"caption":"Kopf"},"image":{"@id":"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/a096a6de30951e12938c6a800eeaa891","name":"Bruno Marotta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kopf.com.br\/kaplof\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8e15f82b4b9672c32c601286a40eb46f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e15f82b4b9672c32c601286a40eb46f?s=96&d=mm&r=g","caption":"Bruno Marotta"},"url":"https:\/\/www.kopf.com.br\/kaplof\/author\/bmarotta\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/posts\/251"}],"collection":[{"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":3,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/posts\/251\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kopf.com.br\/kaplof\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}