Solved

Maximum size of an array

Posted on 2002-07-15
4
216 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 look for a specific file type in a local or remote server directory using PHP.

932 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

13 Experts available now in Live!

Get 1:1 Help Now