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.

categories PHP, WACT
tags memory-usage, pear

Related Posts

  • PHP 5 adoption
  • Manual Memory Management is Dead
  • Comparing PHP with other languages
  • Web Page Loading Performance
  • 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. #1 Harry Fuecks responds...
    May 28th, 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. #2 Harry Fuecks responds...
    May 28th, 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. #3 Jeff Moore responds...
    May 28th, 2004 at 8:39 am

    Very nice, Harry! :)

  4. #4 Lukas responds...
    June 21st, 2004 at 8:45 am

    this issue is fixed in CVS

  5. #5 Jimmy responds...
    June 28th, 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. #6 bharris responds...
    August 8th, 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 pingbacked on April 24th, 2006 at 5:00 pm

Leave a 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

  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Add to Google
  • Share This

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (16)
    • Open Source (14)
    • PHP (95)
    • Software Design (28)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • Sarah Snow Stever  26
      Massimo, arabcrunch, Dubai Web Design, Development [...]
    • The PHP scalability saga continues  17
      vaginal, uceqlehwigi, panties [...]
    • Keywords and Language Simplicity  9
      Programmer, cfbow, olmse [...]
    • PHP 5.1 is out  8
      Preteen, Soma, teedattaltY [...]
    • goto in PHP  39
      jistanidiot, Goldilocks, [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  105
      Massimo, jitesh Shetty, Jesse [...]
    • WordPress BBCode Plugin  24
      ?????? ??, ?????? ??, smolenskiy [...]
    • Why is PHP Popular?  24
      art.ru, agened.ru, visasim.ru [...]
    • nofollow and comment spam  7
      Pwhndvve, Massa, che spavento, Scopmazo [...]
    • Why is PHP Code Considered Hard to Maintain?  25
      bez-riska.ru, Visitor338, Cody [...]
    • PHP Scalability and Performance  7
      youporn, kvz, John Loehrer [...]
  • Pages

    • Tags
  • Recent Posts

    • 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)
    • Keywords and Language Simplicity
    • Improved Error Messages in PHP 5
    • Michigan Taxes Graphic Design Services
    • Ruby versus PHP or There and Back Again
  • Archives

    • 2008: May
    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Log in