[GRLUG] Programming efficiently

John J Foerch jjfoerch at earthlink.net
Tue Sep 25 17:26:41 EDT 2007


Justin Denick writes:
 > If I were to put all the values of the states into an array in an included
 > file
 ...
 > 
 > Where are the elements of the array stored, are they held in the servers
 > memory, or the clients?
 > 
 > So if 50 clients connect, will each store their own variables, or will the
 > variables be stored 50 times in the server's memory?
 > 
 > If the latter is true, than it would make more sense to draw that array in
 > then free the results, rather than include the array as a variable.
 > 

Hi Justin,

Everything in php happens serverside.  Separate invocations of php
have no memory sharing with each other.  PHP imposes a memory usage
limit of 8mb per process by default.

This is the least of your worries, really, if you are writing a
complex system that you intend to maintain over time.  A useful
perspective on programming is to consider that you are controlling
complexity.  The amount of typing involved to type a program is the
least significant source of complexity.

The code in your second method is slightly more abstract than in the
first, yes, but in both, UI and business logic are mixed together.  If
it's a throw-away program to get a small job done, it's no big deal.
If it's a larger application that you will need to maintain over time,
you'll find that this style leads to very complicated programs.  For
example, if you need to change some aspect of the UI, you will have to
go in and edit your business logic, and vice versa.

Typically you would write an abstract interface for your UI, so that
data from your business logic modules can be sent to it, gotten from
it, etc., without their needing to know too much about its
implementation details (for example, that the UI is an HTML document).

To reduce the server resources dedicated to business logic, when you
have a lot of client requests coming in, the general strategy is for
the UI to be able to cache pages it has already made, and serve up the
correct cached document whenever it can.

--John Foerch






More information about the grlug mailing list