How to store and retrieve a heavy page

I have 2 very slow pages on my real estate site that use several Joomla components, lots of RSS and images, so it take over 2 minutes to load those 2 pages as there are way too many HTTP requests. Is there a script out there (prefer PHP) that stores a page, say every hour, and fetches it quickly from memory without running all the scripts on the page each time the page is loaded?
greenerpasturesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Have you got caching enabled?
http://docs.joomla.org/Cache
0
greenerpasturesAuthor Commented:
Yes. I am using Joomla 1.0 site that has several custom components (hence it is very hard to move to the latest Joomla). The site though works very well, except the two heavy pages--which I believe do not use Joomla caching because they they are not part of Joomla core components. THat's why I am looking for an outside script for caching that is not part of Joomla.
0
GaryCommented:
But the full page caching should still work as it is based on the url.
Some things like RSS you will not be able to affect as they are dynamic.
What exactly are the http requests - is this all dynamic stuff (ajax)?
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Ray PaseurCommented:
Here is the design I've used.  You can do something like this by using file_get_contents() to read your slow page into the $htm variable, and file_put_contents() to write the static version of the page.  Accompany this with a CRON job that periodically re-creates the .html version.  You may want to change the way the $uri variable is set.

The success of this strategy will depend on how much of the time is actually being spent creating the dynamic Joomla page, versus how much of the time is spent reading javascript and css files, etc.

<?php // RAY_dynamic_to_static_page.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

// CREATE DYNAMIC VARIABLES FOR OUR STATIC HTML DOCUMENT
$xyz = 'Hello World on ' . date('c');
$get = isset($_GET['q']) ? $_GET['q'] : NULL;
$get = htmlentities($get);

// CREATE OUR WEB PAGE IN HTML5 FORMAT USING HEREDOC NOTATION
$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />
<title>Dynamic/Static Page</title>
</head>
<body>

<!-- HERE ARE THE DYNAMIC VARIABLES -->
<p>$xyz</p>
<p>$get</p>

</body>
</html>
HTML5;

// CONFIGURE A STATIC HTML URL (WITHOUT THE GET ARGS)
$uri = $_SERVER['PHP_SELF'];

// STRIP LEADING SLASH AND CHANGE SUFFIX
$uri = preg_replace('#^/#', NULL, $uri);
$uri = preg_replace('#\.php$#i', '.html', $uri);

// SAVE THE STATIC VERSION OF THE PAGE
file_put_contents($uri, $htm);

// WRITE THE WEB PAGE TO THE BROWSER
echo $htm;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
greenerpasturesAuthor Commented:
Ray,
I got it working very nicely with your code, the page loads in a few seconds! A few questions...
1. How would I set up the cron job to update the page each hour? I am a little confused as to what triggers the page saving and which page do I point the cron to?

Let's say I have: slow-page.html and fast-page.html

Is there some default PHP setting at which the page will refresh on its own?

2. Can you elaborate on "You may want to change the way the $uri variable is set."?
0
Ray PaseurCommented:
If the script works and creates the fast-page version, you've already taken care of #2.

For information on how to set up the CRON job, contact your hosting company.  They almost certainly have an example or tutorial.  It's a little different from one installation to another.
Is there some default PHP setting at which the page will refresh on its own?
No, but you're on the verge of a really good idea.  Every file comes with the ability to identify when it was last written to.  Get the current time from time() and use this function to find out how old the file might be
http://php.net/manual/en/function.filemtime.php 

You can make some kind of rule, like if the times are more than an hour apart, go with the slow-page version to create the latest fast-page version.
0
greenerpasturesAuthor Commented:
So it looks like my new fast-page.htm "wants" to refresh every 2 minutes or so, which is way t0o soon. Any way to adjust your code so that it saves the page for 30 minutes? Otherwise, every 2 minutes or so the page becomes very slow.
0
Ray PaseurCommented:
... "wants" to refresh every 2 minutes ...
How is it expressing its want?  Is there some programming you can show us so we can see what is triggering the refresh?  Are you doing this with CRON or filemtime()?
0
greenerpasturesAuthor Commented:
None. If I keep physically refreshing my browser every 20 seconds or so then I notice that in about 2 minutes the page will stall, slowly reload, and then become fast again loading again.

A cron for every 2 minutes would I think use too much of system resources.
0
Ray PaseurCommented:
I'll need to see the code that makes the decision whether to load the fast page, or rebuild the fast page before producing the browser output.  Without that, I'm just guessing, and there isn't enough time left in life to guess about things that can be observed and finitely determined.
0
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0
greenerpasturesAuthor Commented:
Thank you, Ray. You have helped me a lot on several occasions.

After looking at my file structure, I noticed that your code above is actually producing a brand new page with .html extension (in addition to the .php page). So I created the cron job for the .php page and directed the users to .html page--problem solved.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.