John Tadros
John Tadros

Reputation: 21

Get Cached page ONLY IF apache is down - PHP

I have a requirement to make a page available if apache is down for any reason. The way I thought of it is to make the page "cached" so that it is available always.

However I have 2 problems: - I want the page to be always available (may be I can set the cache limit to a very big number) - When I make the page cached, the browser always retrieves the cached page even if apache is up.

So anyone can advice on what should I do here ? May be there is a better alternative other than the one I am using ?

This is the code I use for reference:

<?php
session_cache_limiter('public');
$cache_limiter = session_cache_limiter();

session_cache_expire(60);
$cache_expire = session_cache_expire();

session_start();

echo "hello world 2222";
?>

Thanks in advance John

Upvotes: 1

Views: 94

Answers (3)

symcbean
symcbean

Reputation: 48387

You can't do this using caching.

In order to handle the request and detect the non-availability of the webserver, you need something which can process http requests and then substitute content when Apache is not available... i.e. a second webserver. And if you've got a second webserver, why not just load balance them.

Upvotes: 0

John Tadros
John Tadros

Reputation: 21

Thanks all for your answers

I managed to do it by setting a cookie that contains the "dc" param to be appended to ajax calls.

And the whole page uses ajax.

So I make a dummy request at the start of the page, if I got no response, I get the cached request from the "dc" parameter set in the cookie

Upvotes: 0

Anthony
Anthony

Reputation: 37065

I'm not sure how this would work. If apache is down, how will this default page get served up? How will the client be directed to the web root? Who is telling the client where this default page is located?

I'm very interested in the idea of "the page is cached". Have you had any success with this after taking apache offline? Does it require that the browser visit the page once before in order to cache the page?

Here's an odd addition to our idea. How about caching some javascript into the page. The javascript attempts to make an ajax call. If it is unsuccessful, it assumes apache is down and then redirects the user to another server's webpage or re-writes the entire page with the "Server is down" page you have in mind.

Not sure it's worth the resources, but it's an interesting idea.

Upvotes: 1

Related Questions