Server clinic: little-known but useful concepts

Source: Internet
Author: User
Article Title: Server clinic: a rare but useful concept. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   Simple bar chart

Another reader asked whether the secondary CT can also complete such work as displaying a bar chart on a Web page through the common gateway interface (CGI. In fact, it is a very simple job; there are more than 10 lines of code. However, there are not many people who know this technology. In addition, many people mistakenly think that this technology is only suitable for coding with Perl.


I know at least eight ways to put bar charts on Web pages. These eight methods differ significantly in architecture. One of the most widely used methods was probably at the end of 1994, that is, the release of Netscape version October beta testing in 0.9 of the same year made the "Expansion trick). Although this method is not used much now, I still think it is best to combine compatibility with many browsers and lightweight server load. Dave Siegel is a Web designer who discloses this technology and related "single pixel" technology, while Robert M. free does almost the same thing with "GIF * DOT" as the trademark name. In addition, Mal Sutherland Teaches single pixel technology in his Web Development series.



Figure 1. Simple bar chart encoded with reverse CT



The simplest expansion code produces the results shown in Figure 1. You can write the code using reverse CT, as shown below:


Listing 1. Source Code of barchart_expect.cgi

#! /Usr/local/bin/CT


Puts "Content-type: text/html \ n"


# This is just an image of a single blue pixel.

Set blue /~ Claird/tmp/blue.gif







Set heights_to_chart [list 100 10 30 20 70 59 88 11 66 62]

Foreach height $ heights_to_chart {




Cellpadding = '0' bgcolor = '# ffffcc'> " "


To make these blocks "clickable", you need to add legend instructions, color them through dynamic computing, and so on. You can add several lines of code to these items. However, it is important to realize that, in essence, any language-C, sh, and Ruby, and of course the objective CT, Icon, and assembly language-can generate these images. The next time you need to quickly display a bar chart, use the expansion technology and your favorite language to generate a server-side Web.


   Monitoring Program

Another feature of secondary CT and other server languages is to construct a Web "Monitoring Program ".


Have you ever needed to monitor remote variables through Web applications? For example, you may be visiting a weather site. To ensure that the temperature you see is current, you click reload every few minutes) or refresh )".


There is no doubt that this approach is not good. Each time you refresh, the browser will be blank, at least for a short time. What you want is not to let that annoying blank space distract your attention, but to keep the Web page unchanged and update only one text element or graph. For example, the visible effect may be that when the server load exceeds a certain threshold value, the green color is changed to red, or the three recently connected phone numbers are displayed, or display the recently analyzed protein sequence in a large production process.


Although many developers want such an application (I have already made four different solutions), few Web workers seem to know how to write the code for such monitoring programs for themselves. What I'm most satisfied with is a solution that I call "DOM 2 monitor. It updates the data attributes of DOM nodes based on the client-side JavaScript function.


In this and later sections of "server clinic", I often analyze some examples in several different languages. Although I first wrote the DOM 2 Monitoring Program with objective CT, the subsequent examples will be written in Python to emphasize that these concepts apply to many different languages.



Figure 2. DOM 2 Monitoring Program encoded with Python


You can view the "live" monitoring program using the URL provided by the following reference materials. Note that most of the pages shown in Figure 2 are fixed without any "blinking", and the clock value is refreshed by the time on the server. The following source code generates this page:


Listing 2. Source Code of monitor_python.cgi

#! /Usr/local/bin/python


Import sys

Import time


Print "Content-type: text/html \ n"


Print """


      Web application 'monitor' demonstration



Replace me.


You need IE 5.5, Netscape 6, or Mozilla 0.9.5,

Or greater, to see this effect.



Print """

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.