Multiplay Labs

tech hits and tips from Multiplay

PayPal PHP SOAP Interface Memory Leak Fix

without comments

Due to the fact that the PayPal SOAP interface relies heavily on exceptions within pear its call to backtrace quickly causes a significant memory leak resulting in long running processes exiting with something like:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 13 bytes) in /usr/local/share/pear/PEAR.php on line 884

Fortunately the fix is quite simple:-

--- /usr/local/share/pear.old/PEAR.php.orig     Tue Feb  2 18:47:42 2010
+++ /usr/local/share/pear.old/PEAR.php  Tue Feb  2 23:24:45 2010
@@ -860,7 +862,7 @@
         $this->userinfo  = $userinfo;
         if (function_exists("debug_backtrace")) {
             if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
-                $this->backtrace = debug_backtrace();
+                $this->backtrace = debug_backtrace( false ); // Don't populate the object reference as this causes circular reference and hence memory leak
             }
         }
         if ($mode & PEAR_ERROR_CALLBACK) {

Written by Dilbert

October 4th, 2010 at 4:24 pm

Posted in Code,PHP

Leave a Reply

You must be logged in to post a comment.