Solved

Maximum size of an array

Posted on 2002-07-15
4
219 Views
Last Modified: 2010-08-05
Hi

I'm building a page which uses arrays to display different content based on the page's url (dynamic pages).

However, it looks like these arrays will end up getting quite extensive, and I was wondering if this can cause problems or latency later on.  In other words: is there a maximum size for arrays (or a point after which it will become too cumbersome for the server to handle properly)?

Thanks!
0
Comment
Question by:IconMan7
  • 2
4 Comments
 
LVL 3

Author Comment

by:IconMan7
ID: 7154302
Ah, yes, before I forget.  They're associative arrays of course.
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 50 total points
ID: 7155116
There probably is a limit, but if you are worried about handling too much info at once, try chopping it up.

Do your arrays hold data for ALL the pages? e.g. Say you have an array of page titles, only 1 title exists per page, so when you say show me the title for page 246, do you get that data from the array which contains all page titles?

If so, then every single page request will have to hold onto a LOT of junk (relavitely) data.

There are several ways you could limit the amount of data per page.

1 - Include files with the name being generated by the page request ...

<?php
$sFile = "inc{$_GET["pageIndex"]}.php";
include $sFile;
?>

2 - Use a DB (much more efficient).


You COULD use the page with the arrays to physically generate the other pages. This is not sound as daft as it sounds.

You currently have 1 page with the arrays in. Maintaining this manually I would assume. Using the manually maintained page with all the arrays, use the arrays to create all the subsequent pages and store them on the server. You would need to have write access to the directory containing the pages. You would only need to re-generate the pages when you made a change to the page holding the arrays.

If the age holding the arrays is also dynamically generated, then instead of using the arrays, simply rely on the source data.

Maybe.

Richard.

0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7155824
It can be tempting to load A LOT of information into a single source file.  This eases maintenance issues, but of course it means that every time that file is "include"d or "require"d PHP has to load and parse the whole thing.

You may want to consider alternatives that load smaller amounts of information, depending on the page to be displayed.

I.e. Rather than having something like...

<dynamic.php>
$page_info = array(
  'home' => array(
    'title' => 'Home Page',
    'description' => 'This is my home page',
    'style' => 'main.css'),
  'sales' => array(
    ... etc
)

... consider using separate files ...

<dyn_home.php>
$title = 'Home Page';
$description' = 'This is my home page';
$style' = 'main.css';

<dyn_sales.php>
$title = 'Sales';
...

This will execute faster with less load on the server, and is still reasonably maintainable.
0
 
LVL 3

Author Comment

by:IconMan7
ID: 7156021
I think that playing with the filenames based on the GET variables in the URL will be the way to go.  Arrays just looked so darn easy to use that I never really considered that possibility.  Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question