Forum Moderators: coopster
...still on the never-ending search for php-performance info...
my navigation menu is composed of a series of arrays. one main one, holding the main sections, and a multi-dimensional array (for the sub-cats) which holds up to 10 sub-arrays each with up to 10 $vars in each.
every time a page is loaded, i loop through the multi-dimensional array and search for 'SCRIPT_URL' to know which link should appear active. depending on the page this can be up to 10 loops.
would it be better practice to cache the html output for the navigation menu and simply return that?
it would mean that each page has an extra disk call (to get the cached output), but it would prevent lots of code looping when traffic is high.
is this good programming logic?
many thanks! :)
p.s. i have timed both page generations and there is no noticeable speed increase
If you are running 15K RPM SCSCI drives, and have 2GB RAM/Dual 2.4Ghz Xeon Processors, I would still take Disk over Memory..
But If you are running on IDE 7200 RPM drives, and have less RAM, I might be more inclined to go the memory route.
Of course there are other variables that come in to play. Traffic levels, what web server software you are using, are you doing SQL/MySQL directly on the Web Server. As all of these variables reduce available RAM.
We run a very disk I/O intensive environment, and found that bumping RAM didn't help much, but 15k RPM SCSI helped dramatically.
>> CSS
i use css. if a link is identified i echo out class="active". :)
-------------------
hi ian,
i have a menu structure in which the sub cats are only visible on the page in question, and the active cat is always displayed at the top of the navigation menu. e.g.:
>active cat
* subcat 1
* subcat 2
* subcat 3
* subcat 4
* subcat 2
>other cat
>other cat
>other cat
>other cat
etc...
so when i query the URL i need a way of identifying which subcategory i am in, which main category this corresponds to, and then i echo everything out.
so i need
* one array which contains all the main cats.
* another array (multi-dimensional) which contains all the subcats.
* a third relational array which identifies the main cats with the appropriate subcats. e.g.
$main_links = (
'Products' => '/products.htm',
'Services' => '/services.htm',
'About Us' => '/aboutus.htm',
'Contact' => '/contact.htm'
);
$sub_links = (
0 => array(
'Product 1' => '/products/product_1.htm',
'Product 2' => '/products/product_2.htm',
'Product 3' => '/products/product_3.htm'
),
1 => array(
'Services 1' => '/services/service_1.htm',
'Services 2' => '/services/service_2.htm',
'Services 3' => '/services/service_3.htm'
);
$relation_links = array(
0 => 'Products',
1 => 'Services'
);
(anyone still with me? ;-)
so i loop through the $sub_links array searching for the URL in one of these.
for ($x = 0; $x <= size_of($sub_links); $x++) {
if (in_array($URL, $sub_links[$x]))
once i have found it, I know which main cat it refers to by accessing the $relation_links array.
then i echo everything out.
wow that sounds complicated! but it works, and for the life of me i can't think of a simpler way to do it.
the problem as i see it with the way you suggest is that the sub category links are only visible on the page in question, so i do not echo out every site link on every page, which would make your suggestion of one large array possible?
of course i might well not be seeing the wood for the trees, and if you can make head or tail of the above and see any glaring anomalies, it is MUCH appreciated ;-)
thanks all! :)
(I know the above doesn't exactly correspond to your site)
You have form post or query string data available to give you all of that info.
The product page your are on is located in $products[$lev3], The section you're in is located in $sections[$lev2] and your main catagory is $main[$lev1].
Where $lev1 = $_REQUEST['lev1']
You can run/not run the echo for subcats based on whether or not $lev3 is populated.
Your arrays don't have to know anything about the rules of your nav structure, they just need to store the data.
I guess I don't see why you're using the urls for identification and not query data? If you've got .htm files calling a dynamic script then you're already using mod_rewrite. Have it make you a query string out of the url. The page designation should tell the script directly which page it is, as opposed to the script having to figure it out.
thank you for explaining!
definitely a case of being far too complicated for my own good ;-)
i shall have to have another complete look at my nav code. i am not actually mod_rewriting, i am exploding the path_info on /, but same difference - i am still left with enough variables to (more) easily identify the links involved.
thanks again.