Solved

Maximum size of an array

Posted on 2002-07-15
4
213 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:
RQuadling 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now