Jump to content

Dynamically append to URL's


Aureole

Recommended Posts

I'll try and give you a realistic example:

 

Let's say we have a website, but the database isn't working, but we have a backup server with another copy of the database.

 

How could I dynamically append say "?secondary_db" to all URLs?

 

<?php
// Pseudo code...

if there is an error connecting to the database append a string to all urls

if the url contains the appended string connect to the secondary database instead
?>

Link to comment
Share on other sites

Many, many ways to do this.

 

1: Attempt server1 every time, if it fails, attempt server2.

-Problem: Could take seconds to timeout, making your page execution time annoyingly slow.

 

2: Trigger a flag in an external file. You would check this file on every page execution, and if the flag is set, use server2. You could then set a cron that continually checks if server1 is up, and when successful, remove the flag from the file

-Problem: Requires reading an external file at every page call, and additional code. Also requires a cron, or external script to remove flag.

 

3: Attempt to connect to server1, if failed, store flag in session. If flag is present, use server2

-Problem: Kinda redundant unless you have a session already started, will attempt to connect to server1 again when session expires

Link to comment
Share on other sites

not that this has anything to do with php -  but you could look into using

the .htaccess file using rewrite_mod and rewrite_mod rules.

you could for example have a rule that says to append a literal string to a url with a pattern matching

algorithm.

not tested:

RewriteEngine On

RewriteRule ^my-literal-page-name\.html$ /my-literal-page-name/anystringyouwanthere  [L]

 

the apache rewrite mod has to be loaded for this to work. but you won't have to restart apache

if you use the .htaccess method.

hope that helps

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.