2019年12月25日 星期三

php xmlrpc decode bug for large size and solution

1. When the response is large than 10MB the xmlrpc decode will return null

https://www.php.net/manual/en/function.xmlrpc-decode.php

Note that from libxml 2.7.9+ there is a limit of 10MB for the XML-RPC response.

If the response is larger, xmlrpc_decode will simply return NULL.

There is currently no way to override this limit like we can with the other xml functions (LIBXML_PARSEHUGE)


2.  solution parse using the

SimpleXML


example:
<?php
        //Enter your code here, enjoy
    $xmlString = <<<EOF
<?xml version='1.0'?>
<methodResponse>
        <params>
            <param>
                <value>
                    <array>
                        <data>
                            <value>
                                <string>Hello</string>
                            </value>
                            <value>
                                <string>Andy</string>
                            </value>
                        </data>
                    </array>
                </value>
            </param>
        </params>
</methodResponse>
EOF;

$xml = new SimpleXMLElement($xmlString);

if ($xml===null || !is_object($xml))
    die('Failed to load xml file.');
    

echo "ok";    

//print_r($xml);
echo $xml->params->param->value->array->data->value->string;
echo $xml->params->param->value->array->data->value[1]->string;

沒有留言:

張貼留言