Create custom CGI. variable

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Create custom CGI. variable

    Does anyone know how I could create a variable that would appear in the #cgi#
    scope ? I have x number of coldfusion servers and on each one of them I want
    to hard code their names, to get around a number of bugs. When you have debug
    info turned on, you see a number of variables, of which I would like to add
    my own 'WEBSERVERNAME'. I tried to add a variable to the environment VAR_IST
    in the coldfusion start script, but I knew it would work, it it somewhere
    in the apache config that I can set it ?? any ideas how to do this ? From a
    cfm template id just like to display on the screen #cgi.webservername#
    Regards

    smartboy Guest

  2. Similar Questions and Discussions

    1. Using a Variable to create the SQL Query
      I need to create a "dynamic" Update query. I want to store the meet of the command in a variable and then reference the variable in in query. ...
    2. Create Variable
      Hi, I wanted to ask, how can I for Simple Connection component, username text field, set a variable? Thanks Lanex:beer;
    3. create a dynamic variable
      Hi ! i would like to know how to create a dynamic variable with flash. I'm getting 2 strings from XML and would like to create a variable named...
    4. How do I create a custom stroke?
      I want to create a stroke that has a shape on it, ie square block which follow a circle path. How can I do this in Illustrator 10? I can't seem to...
    5. create variable before redirection.
      I'm trying to set a variable before redirection. Here is the code: //header("Location: /ManageProfile.php?UserID=".$id); echo("<input...
  3. #2

    Default Re: Create custom CGI. variable

    Well, I'm not THAT experienced, but I think your best bet would be to make a
    cfswitch clause based on the servers serial number. This is a simple server
    variable that you could call, and as long as they all have different serial
    numbers; it should work out fine.

    The location of the variable is:
    Server.ColdFusion.SerialNumber

    If you would like to simplify the deployment of this title you'd like to list
    on the screen, I would suggest creating a tag like<cf_getServerName> and put
    all of your switch/case clauses inside it to set a serverName variable in the
    calling page.

    Example:




    <!---FileName: getServerName.cfm
    Purpose: To name the server that content is coming off of.
    Location: In the customTags folder on the server
    --->

    <!---Set the serverSerialNumber variable to the serial number of the server
    the tag is running on--->
    <cfparam name="serverSerialNumber" default="#Server.Coldfusion.SerialNumber#">

    <!---Name the server based on it's serial number--->
    <cfswitch expression="serverSerialNumber">
    <cfcase value="1st Server's Serial Number Here">
    <cfset CALLER.serverName="Name for 1st Server Here">
    </cfcase>
    <cfcase value="2nd Server's Serial Number Here">
    <cfset CALLER.serverName="Name for 2nd Server Here">
    </cfcase>
    <cfcase value="3rd Server's Serial Number Here">
    <cfset CALLER.serverName="Name for 3rd Server Here">
    </cfcase>
    <cfcase value="4th Server's Serial Number Here">
    <cfset CALLER.serverName="Name for 4th Server Here">
    </cfcase>
    <cfdefaultcase>
    <cfset CALLER.serverName="Whatever you want to call the server if it's
    serial number hasn't been
    listed as a case.">
    </cfdefaultcase>
    </cfswitch>

    Tomdogggg Guest

  4. #3

    Default Re: Create custom CGI. variable

    The serial numbers are all differant but I dont really want to use them as the
    basis for what im doing. I'd prefer to do this with one line of code and
    preferable at application startup. If there was a value that was created at
    the startup of the Coldfusion server that was accessible to all cfm templates
    that would be great for logging, displaying which server served a template, as
    well as a few other simple tasks which can end up being done other ways.

    smartboy Guest

  5. #4

    Default Re: Create custom CGI. variable

    Is there a way to perhaps add a setting to the cf.registry file (in UNIX) which
    I could then call ? eg #server.coldfusion.serialnumber# works fine, could I
    add my own value and have say #server.coldfusion.name# ? Obviously somethings
    in the registry are accessible, but then some arnt... there must be a simple
    way to do this without having to add it to the apache stubb to pass along to
    coldfusion...

    smartboy Guest

  6. #5

    Default Re: Create custom CGI. variable

    > it it somewhere
    > in the apache config that I can set it ??
    This sounded like a webserver question to me, so I had a gander at the
    Apache documentation.

    1.x
    [url]http://httpd.apache.org/docs/mod/mod_env.html#setenv[/url]

    2.x
    [url]http://httpd.apache.org/docs-2.0/mod/mod_env.html#setenv[/url]

    Sounds about right..?

    --

    Adam
    Adam Cameron Guest

  7. #6

    Default Re: Create custom CGI. variable

    So then why not just go with the other option I gave? It's simple enough and
    sets the name to a server variable and you would just stick the code into an
    Application.cfm on each server to make sure the variable exists, and if it
    doesn't, it would set it.

    It is possible to set a server variable of "server.Name", which will exist
    until the server is reset. All you would do to make this one is:

    <cflock scope="server" type="readonly" timeout="30" throwontimeout="no">
    <cfset IsNamed=IsDefined("server.IsNamed")>
    </cflock>
    <cfif NOT IsNamed>
    <cflock scope="server" type="exclusive" timeout="30">
    <cfset server.Name="Server 1, or Server 2, or Server 3, whichever this code
    exists on.">
    <cfset server.IsNamed=true>
    </cflock>
    </cfif>


    Tomdogggg Guest

  8. #7

    Default Re: Create custom CGI. variable

    I actually think this server-scoped option is a better solution than the
    requested CGI-variable one. There's "fewer moving parts" as the webserver
    is left out of the loop, and the config for a a requirement of your CF app
    is handled by CF itself.

    Although as long as you're using a CF version post CF5, you can dispense
    with all that locking carry-on.

    Just have:
    <cfparam name="server.server_name" default="SERVERx">

    There's no chance for a race condition there, so no need to lock anything
    (locking has overhead).

    --

    Adam
    Adam Cameron Guest

  9. #8

    Default Re: Create custom CGI. variable

    When you have one file, being accessed from 2 coldfusion servers, behind a load
    balanced IP, theres no way to determine which of the two servers generated the
    page, using some cfm code to set a variable really doesnt help. Using a
    cfexecute to make a system call works sometimes, but often throws memory
    errors into the logs as well as a few other strange things. I have tried the
    sentenv apache tweak but cant seem to get it to pass it along to coldfusion,
    but I think that is the route that will eventually do what I want.

    smartboy Guest

  10. #9

    Default Re: Create custom CGI. variable

    > When you have one file, being accessed from 2 coldfusion servers,

    Fair enough.
    > behind a load
    > balanced IP,
    The load-balancer might well set a CGI variable of its own here? Depends
    how it's set up. That might be a good palce to do it, if poss. Depends on
    how your set-up is configured, of course.
    > page, using some cfm code to set a variable really doesnt help. Using a
    > cfexecute
    Eek. I wouldn't do that.

    >to make a system call works sometimes, but often throws memory
    > errors into the logs as well as a few other strange things. I have tried the
    For these reasons.

    > sentenv apache tweak but cant seem to get it to pass it along to coldfusion,
    > but I think that is the route that will eventually do what I want.
    How are you looking for it? One annoying and undocumented quirk I
    discovered regarding CGI variables is discussed (of should that be
    "disgust"?) here:
    [url]http://www.cfcentral.com.au/cfaussiePosts.cfm?discussion=cfdump%20error%2Fbug% 3F[/url]

    The bottom line is don't rely on <cfdump> to tell you all the CGI variables
    available, because it doesn't retrieve them all.

    However, if you're just doing a <cfoutput> of it, and it ain't there,
    then... hmmm, yeah, that's a problem.

    If you write a JSP page to dump CGI variables, is it there? Does some a
    perl processor or some other script processor ship automatically with
    Apache that you can knock together a quick CGI script to dump the CGI
    variables and see if the problem lies with Apache or CF? Given the above
    thread, I would assume it's Apache, not CF, to be honest.

    --

    Adam
    Adam Cameron Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139