Gossamer Forum
Home : General : Perl Programming :

why print command doenst work for me ?

Quote Reply
why print command doenst work for me ?
Hello I have a CGI Proxy , I made this code to Prevent the CGI PROXY be runned if the CPU Server load is more than 4.
Code:
open(FILE, "</proc/loadavg");
my $LoadAvg = substr(join('', <FILE>), 0, 4);
close(FILE);
if ($LoadAvg>4) {
print "Content-type: text/html\n\n";
print "sever is busy";

}
else {
# the scrip goes here

}

it works fine I mean, when the server load is more than 4 , it wont run the CGI script but it doenst print "server is busy"

why is that ?

I have put this code just after the variable delcartion.
here is a part of the code that you may like to take a look :

i color the part that I added with RED .


Code:
#!/usr/bin/perl
#
use strict ;
use Socket ;

# First block below is config variables, second block is sort-of config
# variables, third block is persistent constants, fourth block is would-be
# persistent constants (not set until needed), fifth block is constants for
# JavaScript processing (mostly regular expressions), and last block is
# variables.
use vars qw(
$TEXT_ONLY
$REMOVE_COOKIES $REMOVE_SCRIPTS $FILTER_ADS $HIDE_REFERER
$INSERT_ENTRY_FORM $ALLOW_USER_CONFIG
@ALLOWED_SERVERS @BANNED_SERVERS @BANNED_NETWORKS
$NO_COOKIE_WITH_IMAGE @ALLOWED_COOKIE_SERVERS @BANNED_COOKIE_SERVERS
@ALLOWED_SCRIPT_SERVERS @BANNED_SCRIPT_SERVERS
@BANNED_IMAGE_URL_PATTERNS $RETURN_EMPTY_GIF
$USER_IP_ADDRESS_TEST $DESTINATION_SERVER_TEST
$INSERT_HTML $INSERT_FILE $ANONYMIZE_INSERTION $FORM_AFTER_INSERTION
$INSERTION_FRAME_HEIGHT
$RUNNING_ON_SSL_SERVER $NOT_RUNNING_AS_NPH
$HTTP_PROXY $SSL_PROXY $NO_PROXY $PROXY_AUTH $SSL_PROXY_AUTH
$MINIMIZE_CACHING
$SESSION_COOKIES_ONLY $COOKIE_PATH_FOLLOWS_SPEC $RESPECT_THREE_DOT_RULE
@PROXY_GROUP
$USER_AGENT $USE_PASSIVE_FTP_MODE $SHOW_FTP_WELCOME
$PROXIFY_SCRIPTS $ALLOW_UNPROXIFIED_SCRIPTS $PROXIFY_COMMENTS
$ENCODE_DECODE_BLOCK_IN_JS
$USE_POST_ON_START $ENCODE_URL_INPUT
$REMOVE_TITLES $NO_BROWSE_THROUGH_SELF $NO_LINK_TO_START $MAX_REQUEST_SIZE
$QUIETLY_EXIT_PROXY_SESSION
$OVERRIDE_SECURITY

@SCRIPT_MIME_TYPES @OTHER_TYPES_TO_REGISTER @TYPES_TO_HANDLE
$NON_TEXT_EXTENSIONS
$PROXY_VERSION

@MONTH @WEEKDAY %UN_MONTH
@BANNED_NETWORK_ADDRS
$USER_IP_ADDRESS_TEST_H $DESTINATION_SERVER_TEST_H
$RUNNING_ON_IIS
@NO_PROXY
$NO_CACHE_HEADERS
@ALL_TYPES %MIME_TYPE_ID $SCRIPT_TYPE_REGEX $TYPES_TO_HANDLE_REGEX
$THIS_HOST $ENV_SERVER_PORT $ENV_SCRIPT_NAME $THIS_SCRIPT_URL
$HAS_BEGUN

$CUSTOM_INSERTION %IN_CUSTOM_INSERTION

$RE_JS_WHITE_SPACE $RE_JS_LINE_TERMINATOR $RE_JS_COMMENT
$RE_JS_IDENTIFIER_START $RE_JS_IDENTIFIER_PART $RE_JS_IDENTIFIER_NAME
$RE_JS_PUNCTUATOR $RE_JS_DIV_PUNCTUATOR
$RE_JS_NUMERIC_LITERAL $RE_JS_ESCAPE_SEQUENCE $RE_JS_STRING_LITERAL
$RE_JS_REGULAR_EXPRESSION_LITERAL
$RE_JS_TOKEN $RE_JS_INPUT_ELEMENT_DIV $RE_JS_INPUT_ELEMENT_REG_EXP
$RE_JS_SKIP $RE_JS_SKIP_NO_LT
$JSLIB_BODY
$LoadAvg

$HTTP_VERSION $HTTP_1_X
$URL
$now
$packed_flags $encoded_URL $doing_insert_here $env_accept
$e_remove_cookies $e_remove_scripts $e_filter_ads $e_insert_entry_form
$e_hide_referer
$images_are_banned_here $scripts_are_banned_here $cookies_are_banned_here
$scheme $authority $path $host $port $username $password
$cookie_to_server %auth
$script_url $url_start $url_start_inframe $url_start_noframe
$is_in_frame $expected_type
$base_url $base_scheme $base_host $base_path $base_file $base_unframes
$default_style_type $default_script_type
$status $headers $body $is_html $response_sent
%in_mini_start_form
$needs_jslib
$debug ) ;

# Under mod_perl, persistent constants only need to be initialized once, so
# use this one-time block to do so.
unless ($HAS_BEGUN) {

open(FILE, "</proc/loadavg");
my $LoadAvg = substr(join('', <FILE>), 0, 4);
close(FILE);
if ($LoadAvg>4) {
print "Content-type: text/html\n\n";
print "sever is busy"

}
else {


#--------------------------------------------------------------------------
# user configuration
#--------------------------------------------------------------------------

# If set, then proxy traffic will be restricted to text data only, to save
# bandwidth (though it can still be circumvented with uuencode, etc.).
# To replace images with a 1x1 transparent GIF, set $RETURN_EMPTY_GIF below.

$TEXT_ONLY= 0 ; # set to 1 to allow only text data, 0 to allow all
$REMOVE_COOKIES= 0 ;
$REMOVE_SCRIPTS= 0 ;
$FILTER_ADS= 0 ;
$HIDE_REFERER= 0 ;
$INSERT_ENTRY_FORM= 0 ;
$ALLOW_USER_CONFIG= 1 ;




sub proxy_encode {
my($URL)= @_ ;
$URL=~ s#^([\w+.-]+)://#$1/# ; # http://xxx -> http/xxx
$URL=~ s/(.)/ sprintf('%02x',ord($1)) /ge ; # each char -> 2-hex
$URL=~ tr/a-zA-Z/n-za-mN-ZA-M/ ; # rot-13

return $URL ;
}

sub proxy_decode {
my($enc_URL)= @_ ;

$enc_URL=~ tr/a-zA-Z/n-za-mN-ZA-M/ ; # rot-13
$enc_URL=~ s/([\da-fA-F]{2})/ sprintf("%c",hex($1)) /ge ;
$enc_URL=~ s#^([\w+.-]+)/#$1://# ; # http/xxx -> http://xxx
return $enc_URL ;
}

#............ THE SCRIPT CONTINEUS BUT I DONT BOTHER COPYING 400 KB HERE.................

} #I also added this link
Quote Reply
Re: [johnpaul] why print command doenst work for me ? In reply to
What web server are you using? Is $HAS_BEGUN true when you are expecting to get "server is busy"? Is there some other reason that the script could not be running (like some kind of error)?