Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Maximum size of an array

Posted on 2002-07-15
4
Medium Priority
?
237 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 200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

636 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