Solved

Maximum size of an array

Posted on 2002-07-15
4
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

729 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