NYCPHP Meetup

NYPHP.org

coding optimization reference (was Re: [nycphp-talk] PHP andmemory usage)

Mark Armendariz nyphp at enobrev.com
Sat Oct 16 10:12:40 EDT 2004


Here's a pretty good one by John Lim (creator of adodb):

http://phplens.com/lens/php-book/optimizing-debugging-php.php

Mark 

> -----Original Message-----
> From: talk-bounces at lists.nyphp.org 
> [mailto:talk-bounces at lists.nyphp.org] On Behalf Of Marc Antony Vose
> Sent: Saturday, October 16, 2004 7:06 AM
> To: NYPHP Talk
> Subject: coding optimization reference (was Re: [nycphp-talk] 
> PHP andmemory usage)
> 
> Hi there.
> 
> In my post about memory usage, the suggested solutions are 
> pretty much in line with the path I was thinking, but I could 
> probably use some help, at this point in my PHP 'career' with 
> a good reference on coding efficiency.
> 
> Does anyone know of a good website (preferred) or book (second
> choice) that really discusses strategies for script 
> optimization, in terms of performance, of passing by 
> reference vs. not, and how to structure loops for optimal 
> performance, and so on?  How I can profile my projects and 
> spot inefficiencies?
> 
> This is probably all CS 101 stuff, but I'm a self-taught 
> coder, and could use the guidance.
> 
> Thanks,
> 
> Marc
> 
> 
> 
> 
> >Have you tried just increasing the memory limit in the php.ini file? 
> >I think it defaults to 8MB.
> >
> >Of course, that is a temporary measure. The problem is 
> really that your 
> >code doesn't scale. Are you passing by reference? PHP4 makes 
> copies of 
> >variables when you pass them to functions, so you may 
> actually have 2 
> >or 3 (or more) copies of your data depending on how your classes are 
> >setup.
> >
> >Are you merging the complete list with the template and then passing 
> >the resultant array off to be mailed? That's a lot of 
> customized copies 
> >of the template (6,000+) to hold in memory. It's probably 
> the size of 
> >the template that is causing you problems. Adding 1 character to the 
> >template will cause an additional 6,000 characters to be stored in 
> >memory. That eats up lots of memory real fast. To scale it, 
> you would 
> >need to do it in reasonable chunks, or even one at a time, 
> reusing the 
> >variables to "flush" memory.
> >
> >
> >On Oct 14, 2004, at 10:10 PM, Marc Antony Vose wrote:
> >
> >>Hi there:
> >>
> >>This is a very general question, but I don't know where to 
> begin, but 
> >>generally.  I have, over the years built a fairly complex 
> publishing 
> >>system which is installed on several sites.  Recently, I've noticed 
> >>that my mailing list component is choking; PHP bunks out 
> with a memory 
> >>limit error, which is very unfortunate, since there's no way of 
> >>knowing how many messages were sent before this happened.
> >>
> >>I need to address this issue, but I wanted to get people's 
> strategic 
> >>opinions about what to cut out in order to reduce memory 
> consumption.
> >>
> >>Basically, my central data class extracts names and email addresses 
> >>out of a database, stores that in an array.  We're talking around 
> >>6,000 users here...not a huge number, but sizable.
> >>
> >>Then, I loop through the returned users, create a custom 
> message for 
> >>them by replacing codes in a template, and pass it off to a 
> class of 
> >>mine which is just a wrapper for PHPMailer.
> >>
> >>That's the basic structure.
> >>
> >>So, what should I do?  A few salient points:
> >>
> >>: Do objects and arrays eat up a ton of memory?  Should I instead 
> >>select each user separately inside the loop (more database 
> >>connections, but fewer items stored each time)?
> >>
> >>: Should I be unsetting variables as soon as I no longer need them? 
> >>Would this make much of a difference?
> >>
> >>: Anything else I should look at?  My goal here is to build 
> it so it 
> >>will scale upward; this project will eventually have tens 
> of thousands 
> >>of users...maybe hundreds of thousands.
> >>
> >>Thanks much,
> >>
> >>--
> >>Marc Antony Vose
> >>http://www.suzerain.com/
> >>
> >>What can be shown cannot be said.
> >>-- Ludwig Wittgenstein
> >>_______________________________________________
> >>New York PHP Talk
> >>Supporting AMP Technology (Apache/MySQL/PHP) 
> >>http://lists.nyphp.org/mailman/listinfo/talk
> >>http://www.newyorkphp.org
> >>
> >--
> >Brent Baisley
> >Systems Architect
> >Landover Associates, Inc.
> >Search & Advisory Services for Advanced Technology Environments
> >p: 212.759.6400/800.759.0577
> >
> >_______________________________________________
> >New York PHP Talk
> >Supporting AMP Technology (Apache/MySQL/PHP) 
> >http://lists.nyphp.org/mailman/listinfo/talk
> >http://www.newyorkphp.org
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP) 
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
> 
> 




More information about the talk mailing list