[FX.php List] The more you learn the less you know

DC dan.cynosure at dbmscan.com
Sun Aug 20 14:01:53 MDT 2006


On Aug 20, 2006, at 1:55 PM, Jonathan Schwartz wrote:

> $_SESSION['products'] = findProducts ($_GET['search']);

This line troubles me.

This script is stashing the *entire* foundset into a session  
variable. This is horribly inefficient, especially as the foundset  
grows. This is because PHP must load a bunch of data from the disk  
just to read one little bit of it to send back to the page.

I think this design is flawed because if the foundset becomes very  
large the performance will degrade quickly. As they say, it's not  
"scalable." And it is wasteful. If you are only looking at one piece  
of data per page, why load all the other pieces every page load?  
Session variables are loaded every page load and if you retrieve the  
entire recordset from a session variable it is going to be slow.

It's much better to use the groupsize parameter in the find request  
to tell FMP limit the returned data to one record at a time - that  
will be swift.

Take a look at the example I sent using groupsize as a parameter in  
the search query. Also, the snippet largely avoids mixing PHP code  
and HTML (though you'll have to fill in the blanks a bit). The design  
I go for is to use PHP variables in HTML but as much as possible not  
to spread PHP function calls around inside HTML - too hard to read  
for my little brain.

cheers,
dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060820/6cc3c570/attachment.html


More information about the FX.php_List mailing list