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.

20 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. [...]

  8. Elizabeth Noskowski says:
    10/30/2011 at 10:39 am

    Howdy! I know this is kind of off topic but I was wondering which blog platform are you using for this website? I’m getting tired of Wordpress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

  9. a1207763 says:
    11/4/2011 at 9:09 pm

    I’ve said that least 1207763 times. The problem this like that is they are just too compilcated for the average bird, if you know what I mean

  10. dermatologist london says:
    11/5/2011 at 6:45 pm

    Howdy, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you reduce it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any help is very much appreciated.

  11. a keyword research says:
    11/8/2011 at 11:46 pm

    Thank you for your great post! it has been terribly helpful. I hope that you can continue sharing your information with us.

  12. alphaglobaltrade says:
    11/9/2011 at 10:14 pm

    howdy, i make your diary upon character.it’s actually intelligent codified as a import it helped me copiousness. prolong the substantial work.

  13. black friday says:
    11/10/2011 at 11:02 am

    This post is very good thanks to the owner of this blog is to be taken

  14. Micheal Luton says:
    11/15/2011 at 1:29 pm

    a helpful put up many thanks!

  15. Erik Grider says:
    11/16/2011 at 5:27 pm

    I discovered this post helpful

  16. Hertha Stracener says:
    11/19/2011 at 4:58 am

    thanks for this useful put up

  17. atomboygame says:
    1/9/2012 at 6:20 am

    hey, it’s ranking until catch sites with google as a import thanks since the divide that you’ve precondition. commonly, i’m really astonished, but etc.

  18. cooking experience says:
    2/6/2012 at 8:15 am

    KIDS AND RECIPES…

    Only blowing a number of free occasion on Delicious and I discovered this page . Not typically some tips i prefer to understand, however it has been definitely worth time. Many thanks….

  19. Hong Romanowicz says:
    3/8/2012 at 12:40 pm

    Thank you, I have just been searching for information about this topic for ages and yours is the greatest I’ve discovered till now. But, what about the bottom line? Are you sure about the source?

  20. go learn web98. says:
    3/13/2012 at 7:05 pm

    [...]The information mentioned in the article are some of the best available [...]……

    [...]The information mentioned in the article are some of the greatest available [...]……

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 (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  258
      Tuan Lal, Lavagem de estofados, Edward L. Kind [...]
    • php | tek 2008  36
      how to mend ice machine, Akademija Debelih, Odbacena [...]
    • goto in PHP  59
      kasor, Thomas Valdivieso, Murray Ziadie [...]
    • Firefox Extensions for Web Developers  33
      kasor, Website Design Toronto, mobila bistrita [...]
    • Why PHP is easier to learn than Java  68
      kasor, Justina Calvery, Guy Lipton [...]
    • Meta Tag Refresh Faux Paux  43
      html email templates, E-Juice Reviews, image [...]
    • Improved Error Messages in PHP 5  49
      Carroll Tina, Przeprowadzka, Emery Harari [...]
    • Benchmarking PHP's Magic Methods  33
      kayu oyunlar?,dora,oyun,oyna, Benjamin Bejjani, paypal website [...]
    • Microbenchmarks of single and double qouting.  24
      kefir grains minneapolis, sexshop dildo, tuim688 [...]
    • PEAR Templates  17
      Kandice Sansing, car insurance estimates for teenagers, Dale Brence [...]
  • Recent Posts

    • Richard Thomas
    • 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
  • Site

    • Archives
    • Log in
  • Search