Thursday, June 25, 2015

Dear PHP5

Spent the better part of week looking into why a linked list was causing a segmentation fault.

I'm thinking its a memory issue as I was trying to create list with 30833 objects. But the behavior was odd. I'd actually get a partial web page back from apache, ...which meant the list completed initialization.

I managed to drive memory consumption from 17M to 30M for the same linked list of objects. One system had no memory constraint enforced on php, while the other limited php to 128M. Not a memory problem.

Further, the entire set of 30833 records obtained from a mysql query were easily blown into an array and accessed without issue. Not an array problem.

Turns out there's some practical limit to the number of objects php can manage during script shutdown (and garbage collection?).  I managed to break it at 22768 objects in the linked list on two different systems. There were likely also a handful of additional objects I created, but the segfault occurred when the linked list hit 22768 objects.

...and then I found the discussion on the web that referenced a fellow who had nested the creation of 40000 objects and experienced the same behavior. Further, one of the comments referenced a PHP bug report that had been marked 'Wont Fix' because 'if it hurts when you do that, you shouldn't do that.'

While I went in search of that bug report, I did not find it.

However, I did place a protective limit on the number of objects that will be added to the linked list. And, I added a pagination capability to the sql query. Now, I got to thinking, ...why cant PHP add a limit to the number of objects its willing to create and throw an exception when things begin to get dicey? Hey, I'd prefer learning a week ago that I had simply created too many objects...

#smh




No comments:

Post a Comment