php

php json_decode not working for large string


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


Solution

  • 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