ZF-8869: Memory leak in xml-rpc client.

Issue Type: Bug Created: 2010-01-19T06:18:11.000+0000 Last Updated: 2012-05-30T14:11:39.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Gonzalo Martinez (gmartine) Assignee: Michelangelo van Dam (dragonbe) Tags: - Zend_XmlRpc_Client

Related issues: - ZF-8457

Attachments: -


When using "$XmlRpcClient->call($method, $args);" in a loop structure, after a few rounds, I got Php's memory exhaustion message.

I traced the leak to "Zend\XmlRpc\Client.php" line 351 where the code is;

<pre class="highlight">
$params[$key] = Zend_XmlRpc_Value::getXmlRpcValue($param, $type);

I did the trace by placing a "memory_get_usage();" before and after the line and see the results (there is probably a better way).

My app is running on a Windows XP / SP3, using php 5.2.12 and ZF 1.9.7.

This is my first time reporting a bug, if I omitted some info or not reporting the right way please let me know and will make the necessary corrections.

Regards, Gonzalo.


Posted by Lars Strojny (lars) on 2010-01-20T16:11:40.000+0000

Thanks for the bug report. Could you provide me an example of the parameters you are passing to Zend_XmlRpc_Client::call()?

Posted by Gonzalo Martinez (gmartine) on 2010-01-21T06:39:21.000+0000

Hi Lars,

Will attach all the info I think relevant.

I've just did run the loop for about 30 secs, that did perform four xml-rpc client calls, each with $args of around 400K each.

I am attaching all the info I could get from it.

i) graph of process memory consumption.

ii) zip file containing 12 files, 3 for each call, eg; # 1st_args.txt is print_r() of the $args passed in the call. # 1st_request.txt is the captured http request. # 2nd_response.txt is the captured http response.

On the client's side the line making the call goes like;

<pre class="highlight">
$result = $XmlRpcClient->call($method, $args);

where $method is a string and $args is "array($queries)" being $queries another array.

On the server's side the head of the method handling the xml-rpc call is;

<pre class="highlight">
* @param struct $queries
* @return struct
public function actondbms($queries) {

Regards, Gonzalo.

Posted by Gonzalo Martinez (gmartine) on 2010-01-21T06:40:30.000+0000

See comment for files content description...

Posted by Patrick Schwisow (patrick.schwisow) on 2010-02-18T11:27:07.000+0000

I believe this issue is related to the addition of an XML generator based on XMLWriter. If the XMLWriter extension is enabled, Zend_XmlRpc_Value defaults to using it.

Following an update of my local version of Zend Framework, one of my scripts went from comfortably fitting in 512M to needing 2G. I added

<pre class="literal">
Zend_XmlRpc_Value::setGenerator(new Zend_XmlRpc_Generator_DomDocument());

before my call to new Zend_XmlRpc_Server() and the memory usage is back down to normal levels.

Posted by Patrick Schwisow (patrick.schwisow) on 2010-02-18T12:49:52.000+0000

OK... I'll revise my statements. It is now running out of memory only some of the time.

Posted by Sven B. (susouke) on 2010-09-03T01:22:10.000+0000

Hi guys,

we can confirm this problem. We have a cron-script which runs in an infinity-loop and uses also the Zend_XmlRpc_Client. The memory usage grows minute for minute.

It really would be nice if we had an solution or workaround for this issue.

Posted by Christoph Roensch (croensch) on 2011-05-27T02:14:36.000+0000

Succesfully reproduced it on Zend Server 5.1.0 (php-5.3.5-nts-Win32-VC9-x86). The memory usage increases slightly in my Simulation, but with the fix it is constant and much faster.

Manual for XMLWriter::flush()

Posted by Ralph Schindler (ralph) on 2011-05-28T17:51:48.000+0000

I am not sure what the issue is, both the DomDocument and XmlWriter generators operate the same way. They are capturing all values passed through Zend_XmlRpc_Value::getXmlRpcValue() and keeping them in-memory (as I think I expect them to as you are using a static generator). If you remove the generator from the equation, then memory usage is constant.

<pre class="highlight">


// be sure to use the leaky generator
//$generator = new Zend_XmlRpc_Generator_XmlWriter();
$generator = new Zend_XmlRpc_Generator_DomDocument();

// test a thousand times
for( $i = 0; $i < 1000; $i++ ){
  $targetValue = str_repeat('*', 1000); // 1000 stars
  $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($targetValue, Zend_XmlRpc_Value::XMLRPC_TYPE_STRING);
  $output = $xmlRpcValue->saveXml();
  // report sometimes
  if( $i%100 === 0 ){
    $mem = floor(memory_get_usage()/1024);
    echo "KB $mem\n";
  // writing output to disk
  file_put_contents(__DIR__ . '/tmp/' . str_pad($i, 4, '0', STR_PAD_LEFT) . '.output', $output);
  // clean
  unset($output, $targetValue, $xmlRpcValue);

Try that with a variety of different runs and examine the output files.

I am inclined to close as not an issue.

Posted by Christoph Roensch (croensch) on 2011-05-29T15:04:24.000+0000

You're right. I was mislead by the description and only tested Zend_XmlRpc_Value.

I've read through the module now and found out that only $generator->saveXml() gets called. Also $xmlRpcValue->saveXml() is never called. If it were called the user would have to call $generator->flush() beforehand, else it would return xml of other values that we're generated before.

However, that is not the problem, Request/Response and Client flush the generator correctly. I reproduced Zend_XmlRpc_Client::call() and now i'm as sure as you that there is no leak.

I'm voting for a close as not an issue, i also have no issue with this in production, i just wanted to bug hunt :)

Posted by Patrick Schwisow (patrick.schwisow) on 2011-05-31T14:21:47.000+0000

It's possible that this is the same issue that was fixed in ZF-9504. I think you should look over that ticket and also ZF-8457 before calling this one closed (duplicate).

Posted by Michelangelo van Dam (dragonbe) on 2011-08-26T15:56:17.000+0000

Patched in r24402, ready to deploy

Had some additional test runs.

Can't see why it was set to false in the first place (r19561)

Posted by Kazusuke Sasezaki (sasezaki) on 2012-05-30T14:11:39.000+0000

I found r24402 fix is reverted at r24480…

So, is this Memory leak issue is resolved?

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.