-2

can anyone please help me to sort out json_decode issue , here is my json string which is working fine -

{"323":"723","317":"704","316": {"date":"28\/12\/2016"},"314":"701","315": {"area":"sdfgdfg"}}

but if I add one more key value pair then json_decode function does not work.

{"336":"761","323":"723","317":"704","316": {"date":"28\/12\/2016"},"314":"701","315": {"area":"test"}}

2nd string is not working , however at my local system both strings are working fine , what are the php config parameters I need to check ? I have increase memory limit , max execution time and max post size what else I need to check , please help.

updated here are my codes -

$arrProducts = array(
        array(
            "product_id" => $_REQUEST['product_id'],
            "qty" => $_REQUEST['quantity'],
            "options" => json_decode($_REQUEST['product_options'], true),
            "sku" => $_REQUEST['sku'],
            "store_id" => 1
        )
    );
print_r($arrProducts);

it prints blank array for the 2nd string.

I have checked error log , it shows - PHP Warning: Unknown: POST Content-Length of 274 bytes exceeds the limit of 256 bytes in Unknown on line 0

13
  • could you please provide the code in question, too? i'm guessing it has nothing to do with json_decode itself. Commented Dec 21, 2016 at 8:25
  • Check for errors using json_last_error_msg() Commented Dec 21, 2016 at 8:26
  • Your second string decodes without any problems: eval.in/701965 Commented Dec 21, 2016 at 8:26
  • Unable to replicate any issues - json_decode on the above string works fine. Commented Dec 21, 2016 at 8:27
  • 2
    if that's not working only in your live server then try checking your apache error log in your live Commented Dec 21, 2016 at 9:00

2 Answers 2

1

Here the question is misleading, the issue that you are facing is not that json_decode fails to decode rather the POST maximum size is exceeding

You may find something like the following in your php.ini file

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 256

Change the above to

post_max_size = 8M

ie, 8M as post size limit

And if you are using apache you may need to change .htaccess aswell. Here is the reference for #post_max_size

Sign up to request clarification or add additional context in comments.

1 Comment

actually I was not able to debug it , thank you , it is working now.
-2

There can be another reason for the POST data being empty : sys_temp_dir

Check your php logs for errors like :
PHP Warning: PHP Request Startup: Unable to create temporary file, Check permissions in temporary files directory.
PHP Warning: PHP Request Startup: POST data can't be buffered; all data discarded

It seems that for requests with large amounts of data, PHP will store them as temp files in the temp dir.

This dir is defined an init-param : sys_temp_dir

If its set incorrectly, or is not writable, temp files cannot be created and the large request data is discarded.

Also, enabling php-fpm could cause this issue, as per my webhosting provider

2 Comments

What makes you think that this setting is related, and that this influences how different string lengths are consumed?
It is never appropriate to post duplicate answers on multiple pages. If the questions can be resolved with identical answers, then perhaps you should be voting/flagging to close one of the questions as a duplicate of the other. If the questions are significantly different, then your answers should also be significantly different. Please take a moment to decide if/how you wish to edit/delete one or more of your answers. We would rather you curate your content so that the community doesn't need to intervene.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.