Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« WordPress BBCode Plugin
PEAR Templates »

Rephlux and PHP memory usage with a PEAR surpise

May 27th, 2004

Jon Ramsey came up with a continuous integration tool called Rephlux. Rephlux periodically checks out your code from CVS and runs your unit tests on it. It produces a RSS feed of test failures and a RSS feed of CVS revisions. How cool is that?

In the future it should be possible to automatically build releases and documentation when all the tests pass. Hopefully, this will help improve our record of releasing on the WACT project. With one formal release in nearly a year of active development, our record is dismal as Harry diplomatically points out.

Jon is running Rephlux remotely for WACT right now because we are having a problem getting our full test suite to run in the 8M limit that sourceforge imposes on PHP. We have 97 test cases, 541 test functions, and 1927 assertions in our test suite. This will only grow. The full test suite includes over 350 PHP files when it runs.

Since there isn’t much we can do about unincluding files to free up memory, I decided to take a look at the data that gets stored to see if there was any low hanging fruit there. I wanted to look and see if any of the code we are using keeps any data in global variables that it might be able to release when done to allow the space to be garbage collected.

So, I added a quick and dirty little hack to get an idea of the size of the various global variables that were left over after a test run.

 
    foreach (array_keys($GLOBALS) as $key) {
        echo "$key=" . strlen(serialize($GLOBALS[$key]));
    }
 

Most of the globals that were left over were tiny, but there was one that stood out. That was something from PEAR:
 
_PEAR_destructor_object_list=146270
 

Looking in to this further I found that the PEAR base class registers a rather dubious destructor for every object that inherits from it:
 
    function _PEAR() {
        if ($this->_debug) {
            printf("PEAR destructor called, class=%sn", get_class($this));
        }
    }
 

To support this gem, PEAR puts a reference to every object instance ever instantiated that inherits from PEAR into the global variable _PEAR_destructor_object_list. There the object stays until the deconstruction shutdown function is called. This reference prevents garbage collection of any of objects inheriting from PEAR or the memory they reference during the lifetime of the script. And it does this for no good reason at all.

I’ve expressed my opinion of pear.php before and this only reinforces it.

The only PEAR module that WACT requires is XML_HTMLSax, a handy parser for HTML with an XML parsing interface. I’ve always been a little bit uncomfortable with its dependency on pear.php and the deployment issues that this introduces into WACT. WACT also has optional components that reference other PEAR packages, such as PEAR::DB, PEAR::MDB and PEAR::MDB2. Fortunately a more typical WACT use case only instantiates a handful of PEAR objects.

Filed Under

  • PHP

Related Posts

  • PHP 5 adoption
  • Manual Memory Management is Dead
  • Web Page Loading Performance
  • Comparing PHP with other languages
  • API Design
You can leave a response, or trackback from your own site.

7 Responses to “Rephlux and PHP memory usage with a PEAR surpise”

  1. Harry Fuecks says:
    5/28/2004 at 2:01 am

    Nice discovery ;)

    Just started sorting out HTMLSax BTW – it’s now under PHP’s CVS here and have already elimated the PEAR dependancy this example – basically my fault for making assumptions about comment syntax – Word generates bizarre stuff like: <![endif]–>

  2. Harry Fuecks says:
    5/28/2004 at 7:26 am

    HTMLSax 3.0.0 is out and PEAR.php is gone (apart from some lazy includes on errors that WACT will never encounter) – updated WACT for the (slightly modified) API. Best make sure you have the latest.

  3. Jeff Moore says:
    5/28/2004 at 8:39 am

    Very nice, Harry! :)

  4. Lukas says:
    6/21/2004 at 8:45 am

    this issue is fixed in CVS

  5. Jimmy says:
    6/28/2004 at 9:22 am

    In the CVS it works fine, its just that in the earlier version people were having problems with it.

    But either way, nice!

  6. bharris says:
    8/8/2004 at 8:36 pm

    Jeff…thanks for the ‘memory check hack’. I needed something to make memory usage measurements. Your ‘roll-your-own’ check was very handy indeed.

  7. SitePoint Blogs » Simple Test Remote Testing says:
    4/24/2006 at 5:00 pm

    [...] For reasons explained by Jeff here, we’ve been looking for ways to run WACT’s test suite in a way that won’t run into PHP’s memory limit and the obvious solution is execute the tests in smaller groups over the network, meaning Apache will create a new child for each group, each child having a fresh chunk of memory to gobble up. [...]

Leave a Reply

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (17)
    • Open Source (14)
    • PHP (98)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Benchmarking PHP's Magic Methods  12
      Article Marketing Strategy, Magento Development, Vance Lucas [...]
    • Improved Error Messages in PHP 5  32
      Terry Nessel, css, Amsterdam [...]
    • Keywords and Language Simplicity  11
      kim kardashian sex tape price, nokia, per Rechnung bestellen [...]
    • flickr case study  3
      bookmarking demon software, php-trivandrum.org, Harry Fuecks
    • rsync to remote server via ssh  7
      Burton Haynes, James, Mike [...]
    • Yahoo YUI wins JavaScript Library Wars  10
      Lera Bride, Scott, Jeff [...]
    • OOP is Mature, not Dead  15
      Avery Depew, Fernando, deltawing [...]
    • Ruby versus PHP or There and Back Again  10
      Solar Pumps, Amsterdam, Hari K T [...]
    • Looking Towards the Cloud  22
      Driver License, Jamel Sawyer, enculez. [...]
    • ZendCon: Writing Maintainable PHP Code  8
      IT Ninja, nicopico, Arif [...]
  • Recent Posts

    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
  • Site

    • Archives
    • Log in
  • Search