Solved

Need simple efficient script

Posted on 2002-04-17
39
308 Views
Last Modified: 2013-12-25
Hi I need a simple script where i can define a URL to a banner, i´ll try to explain:

I would like to be able to have a script placed on fx. domain.com/cgi-bin/bannermanager/

where i can link like this:
<src="http://www.domain.com/cgi-bin/bannermanager/banner1.cgi"> instead of using the fixed banner image name/URL  so i can define where banner1,banner2 ect. is located, and only need to change their location in the script.

this should not be so hard, the real problem lies in that the script will be have like 10-15 requests pr sec. = 1 million requests pr day approx.

So the script needs to be very small, and im not so techie, so i dont know how hard this will be on the server?  it will be placed on a dedicated server ofcouse, but still...maybe its better to make it in php i dont know?

is this possiple?

Regards

0
Comment
Question by:nicce
  • 16
  • 16
  • 3
  • +4
39 Comments
 

Author Comment

by:nicce
ID: 6948900
Hmm? im usually getting a response very quickly..wass up? :-)
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6949318
nicce,

"..simple script where i can define a URL to a banner, ..."

You can find a bunch of free, & commercial, scripts that might be of interest to you.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Advertisements/

Hope that helps.
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6950407
nicce,
big nose boird has some excellent perl cgi free scripts.  I have used some of these before and can definately reccommend the banner one:

http://www.bignosebird.com/cgi.shtml

regards
Peewee
0
 

Author Comment

by:nicce
ID: 6950580
I thought about doing it like this
html:

<src="http://.domain.com/banner.php">

banner.php script:
<?
header("Location:http://www.bla.com/banner/banner.gif");
?>

I just the simpleast way to do this, but i dont know php very well, so im not sure if its demanding on the server?

Regards Nick

0
 
LVL 5

Expert Comment

by:Peewee
ID: 6954101
nicce,

is this is sort of thing you want?  you pass this script a redirect value, ie http://www.domain.com/cgi-bin/bannermanager/banner1.cgi?redirect=1 and it counts add to a count and redirects your browser to a particluar located specified within the text file:redirect.txt.

let me know if you need more help
Peewee

I've enclosed a sample text file in the format index, url, count:
========
1,www.hotmail.com,2
2,http://www.sky.com,0
3,www.experts-exchange.com,0
4,www.bbc.co.uk,0
5,http://www.avfc.co.uk,3
===========

#!/usr/bin/perl


use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q =  new CGI;

$form_redirect = '1';
$form_redirect = $q->param('redirect') || die "no redirect has been passed from the form";


my $location;

### read access
open (DB,"<redirect.txt") || die "cant open DB:$!";
@records = <DB>;
close (DB);


###write access
open (FILE,">redirect.txt") || die "cant open DB:$!";

foreach my $record (@records)
{
     chomp $record;
     my ($db_id, $db_site, $db_counter) = split (/,/,$record);
     
     if ($form_redirect == $db_id)
     {
          ### add counter and redirect browser
          $db_counter++;
          $location = $db_site;
          print FILE "$db_id,$db_site,$db_counter\n";
     }
     else
     {
          ### rewrite contents back to the file
          print FILE "$db_id,$db_site,$db_counter\n";

     }

}


close (DB);
print "Location: $location\n\n";

0
 
LVL 3

Expert Comment

by:FlamingSword
ID: 6954344
.
0
 

Author Comment

by:nicce
ID: 6955984
Peewee, this is much to complicated, take a look at what i posted :) 1 script pr banner url, and its only a redirect nothing else, and i would prefer to just hardcode the banenr url in the script, and then i´ll change it there if needed.
I want to know if the solution i posted is the most effecient one, or there is something i should consider at 1 millions requests pr day.
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6959477
nicce,
if you just need a simple solution which will run the risk of been used an excessive amount you should be using a client side technique rather than a servere side, this  will avoid any problems with your server.

I suggest therefore that a javascript banner solution would be more beneficial to you.

have a look at:

http://www.javascript-page.com/banrot.html

Does this make more sense to you.

regards Peewee
0
 

Author Comment

by:nicce
ID: 6959668
I don´t ahve the option to use a client side solution because i need to be able to send the url to the banner (the relative url) to the company who are advertising my banner, this ahve to be the direct url to the image, or in my case to the small script that contains the image url.
0
 

Author Comment

by:nicce
ID: 6959724
what about this solution?

<src="blabla.com/banner.php">


banner.php script:
**********************'
<?  
Header( "Pragma: no-cache" );  
Header( "Expires: Monday 01-Jan-80 12:00:00 GMT" );  
Header( "Content-type:  image/gif");  
readfile ("./mypic.gif");
?>
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6959751
nicce,
ok given what you say here is a simplified server side solution.  It will retrieve the url from a text file.  All the url's are stored in a single text file:

1,www.hotmail.com
2,http://www.sky.com
3,www.experts-exchange.com
4,www.bbc.co.uk
5,http://www.avfc.co.uk

The perl script simply reads the file and redirects the user, no counting is does etc.  It is very basic in what it does. You would pass the index number of the text file to the perl script to associate the location.

You could further speed this up by hardcoding the the values out of the text file and into the perl script.

This should answer your question as i understnd it.  I have associated a url with a banner givinh you a quick and precise solution.  If i have missed any of your points or interpreted them incorrectly, please take the time to fully elobarate as this will considerably quicken the time to which you will get the solution you need.

regards Peewee

#!/usr/bin/perl


use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q =  new CGI;

$form_redirect = $q->param('redirect') || die "no redirect has been passed from the form";


my $location;

### read access
open (DB,"<banner.txt") || die "cant open DB:$!";
@records = <DB>;
close (DB);


foreach my $record (@records)
{
     chomp $record;
     my ($db_id, $db_site) = split (/,/,$record);
     
     if ($form_redirect == $db_id)
     {
          $location = $db_site;
          last;
     }
}

print "Location: $location\n\n";

0
 

Author Comment

by:nicce
ID: 6959832
i only have 1 url so why not store it inside the script?
0
 

Author Comment

by:nicce
ID: 6959834
and is perl not slow, considering the big ammounts of requests it will get? i don´t know im just checking :-)
0
 

Author Comment

by:nicce
ID: 6959862
I don´t ahve the option to use a client side solution because i need to be able to send the url to the banner (the relative url) to the company who are advertising my banner, this ahve to be the direct url to the image, or in my case to the small script that contains the image url.
0
 

Author Comment

by:nicce
ID: 6959865
ehh? the last comment ( i don´t have the option...)is not supossed to be there..weird
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6959988
nicce,
I've embedded the url's in the script, so there no text file here, hence it faster still.

#!/usr/bin/perl


use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q =  new CGI;

$form_redirect = '1';
$form_redirect = $q->param('redirect') || die "no redirect has been passed from the form";


my $location;

### read access
open (DB,"<redirect.txt") || die "cant open DB:$!";
@records = <DB>;
close (DB);


###write access
open (FILE,">redirect.txt") || die "cant open DB:$!";

foreach my $record (@records)
{
     chomp $record;
     my ($db_id, $db_site, $db_counter) = split (/,/,$record);
     
     if ($form_redirect == $db_id)
     {
          ### add counter and redirect browser
          $db_counter++;
          $location = $db_site;
          print FILE "$db_id,$db_site,$db_counter\n";
     }
     else
     {
          ### rewrite contents back to the file
          print FILE "$db_id,$db_site,$db_counter\n";

     }

}


close (DB);
print "Location: $location\n\n";

0
 
LVL 5

Expert Comment

by:Peewee
ID: 6960008
nicce,
Perl is not slow it is a quick program.  However the CGI protocol which runs on your server is a different matter.  Everytime you run a perl script you have to invoke the cgi method which is resource expensive.

You can significantly increase the speed of your scripts by using mod_perl which is compiled into your server.  You will then need to assocaite your specific Perl scripts with this fast mod_perl handler. Alterntaively you can use fast cgi for this solution.  I suggest that you look at for more information on these products and they are not supplied in default installations of apache, assuming you have apache - howver these are question in themselves:

http://perl.apache.org/guide/    
http://www.fastcgi.com/

regards
Peewee
0
 

Author Comment

by:nicce
ID: 6960209
thanks for all this help, i just dont get it, what is that .txt file you are referring to?
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6960382
nicce,
my apologies this should be what i posted for the last perl script without the need for an extrenal file, ie the url are hardcoded in the perl script..
=================================

#!/usr/bin/perl


use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q =  new CGI;

$form_redirect = $q->param('redirect') || die "no redirect has been passed from the form";


my $location;
my @records = qw(1,www.experts-exchange.com 2,www.hotmail.com);

foreach my $record (@records)
{
     chomp $record;
     my ($db_id, $db_site) = split (/,/,$record);
     
     if ($form_redirect == $db_id)
     {
          $location = $db_site;
          last;
     }
}

print "Location: $location\n\n";

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:nicce
ID: 6960433
Peewee, im still confused? sorry, but i want the URL to the banner embedded in the script, and then i´ll use the url to the script instead of linking to the fixed <img src="bla.gif">  => <img src="bla.cgi"> or what ever ...
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6960548
nicce,
ok i think i understand what you actually want. Would you like a perl script that produces the path to a graphic and assocaites a url with it?  I think your thinking in terms of PHP whilst i'm thinking in terms of perl.

let me do some thinking here!

do u want a PHP or Perl script?

peewee
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6960567
nicce,
i think what i have given you is doing the job that you seem to be asking except its in Perl & not PHP.

You will be hardcoding your html to execute a perl script when you click on a banner, this will redirect the  browser to a particular url depending upon which url you would like to associate with a particular banner.

is that it, is this what you need or do u want more?

regards Peewee
0
 

Author Comment

by:nicce
ID: 6960641
Peewee: we are totally misunderstanding eachother...

Look at the post i made where i write my idea of making it work :) but i´ll try to explain it again, its a very simple task,

I am advertising on some websites, those websites wants a banner URL from me every month, this gives me some problems if i want to change the placemant of the banner during the month maybe because of downtime on the server hosting the banners ect.

So thats why i want this small script that ahve the banner url embedded so i have the flexibility to change the banner URL inside the script instead of contancting the sites that are linking to it....

i cant explain this better i think...


i simply want to be able to send the banner url in this format: http://www.mysite.com/banner1.cgi
instead of http://www.mysite.com/banner.gif

Nick


 
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6962346
nicce,
is this what you would like?

regards Peewee

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

print <<EOF
<a href="http://www.mysite.com">
<img src="http://www.experts-exchange.com/v3.0/images/kpro-ad.gif">
</a>
EOF


0
 

Author Comment

by:nicce
ID: 6963086
Peewee..i give up, i think im explaining it totally as its supposed to be..sorry, but thanks for you efford...

this is a very easy task...i hope someone else reads this thread !


i want to achive this:
<img src="http://www.experts-exchange.com/banner.cgi">

and the .cgi should contain the BANNER URL

a banner URL is the location of the banner..like:
 "http://bla.com/banner.gif"
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6963399
nicce,
i would very much like to answer your question but this is beginning to be quite difficult as there appears to be ambuiguity as to what you actually want. Perhaps you should further address things here, as if it was clear, simple and well explained many other experts would have posted on this question.

you have stated:
i want to achive this:
<img src="http://www.experts-exchange.com/banner.cgi">

then why not just code this in your html? Do you really need a cgi script to generate this line?==========================================

you also stated:

and the .cgi should contain the BANNER URL

a banner URL is the location of the banner..like:
"http://bla.com/banner.gif"

then an example banner.cgi would be:
===============================
#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

print "Location: http://www.experts-exchange.com/v3.0/images/kpro-ad.gif\n\n";

=============================


ok, so i know this answers your point but i also know that this makes no sense, so it must be incorrect.

Are any similar or live examples of what you want?

I've included a html form to go with this as an example:

<HTML>
<HEAD>
<TITLE></TITLE>
<META name="description" content="">
<META name="keywords" content="">
<META name="generator" content="CuteHTML">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<!--Don't forget to add your FREE HitBOX statistics to your web page. To
do so, click on Tools\Online Services\Add statistics...-->
<img src="http://www.experts-exchange.com/v3.0/images/kpro-ad.gif">
<img src="http://localhost/cgi-bin/gif.pl">
</BODY>
</HTML>

regards Peewee
0
 

Author Comment

by:nicce
ID: 6963959
hehe thanks for posting even though this is a hard one, the problem is that you are misunderstanding what i say, or that im a bad explainer!! hehe


*you have stated:
*i want to achive this:
*<img src="http://www.experts-exchange.com/banner.cgi">

*then why not just code this in your html? Do you really *need a cgi script to generate this line?*==========================================

i don´t need anything to genrate this line i need the cgi. script!!!

I need the simple cgi. script that is inserted instead of the direct url to the banner picture...this is what is have written 10 times i think..hehe

*you also stated:
*and the .cgi should contain the BANNER URL
*a banner URL is the location of the banner..like:
*"http://bla.com/banner.gif"

yes exactly..
read my first post again, its my own solution on the problem, i posted here to get a bulletproof version:
HTML
<src="http://.domain.com/banner.php">
******************
banner.php script:
<?
header("Location:http://www.bla.com/banner/banner.gif");
?>

this works, but im not sure if it can handle 1 million requests pr day...
so i posted it here.

so again, im not searching for anything that will output any cgi urls...but the small cgi/php/ whatever script..maybe my own is the best...??


Nick

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6964814
didn't read all the comments completely, but sounds that they all try to minimize the script (or use JavaScript, which is useless:).

The culprit for 1 million request a day is the fork to the interpreter (for perl, shell, whatever, ..) or runtime loader (for binary programs) of the CGI.

You need a solution which avoids the overhead of these forks, the size and complexity of this small script doesn't matter then.

If you have an Apache server, then mod_perl might be a solution (sorry, I'm not familar with it for 1 million requests/day).
Or check out FastCGI at http://www.fastcgi.com/
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6965191
nicce/ahoffmann,

i've alreay suggested the fast-cgi and mod perl option and of course a javascript option.  As i mentioned previously these will all aid in perfomance terms with regards to your server.

You dont seem to have commented on these thoughts.

regards Peewee

 
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6965682
Peewee, you've been first :-)
IMO thinking about anything else (except faster hardware) is wasting time.
0
 

Author Comment

by:nicce
ID: 6965853
peewee, i think its because i jsut looked at your codeing and its totally wrong regardign the task i want it to do.. and i don´t knpw what fast-cgi is, and wat just looking for a codeing solution.

nick
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6973337
Listening.
Moondancer - EE Moderator
0
 

Author Comment

by:nicce
ID: 6974299
it ahve been quiet lately..i think my question can´t be answered
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6974489
"not possible" or "cannot be done using" scripts" or you need to change something else" is an answer (as suggested by Peewee and me, for example FastCGI and mod_perl)
0
 
LVL 5

Expert Comment

by:Peewee
ID: 6976996
nicce,
both fastcgi and mod_perl are coding methods of increasng performance for cgi scripts..

i suggest that you look these over and see if are able to use these methods:

http://perl.apache.org/guide/  
http://www.fastcgi.com/

regards Peewee
0
 
LVL 5

Accepted Solution

by:
Peewee earned 300 total points
ID: 7159246
chaps,
this question is dead!


my final thought are from nicce's quotes:


*you have stated:
*i want to achive this:
*<img src="http://www.experts-exchange.com/banner.cgi">

*then why not just code this in your html? Do you really *need a cgi script to generate this line?*==========================================

i don´t need anything to genrate this line i need the cgi. script!!!

I need the simple cgi. script that is inserted instead of the direct url to the banner picture...this is what is have written 10 times i think..hehe

*you also stated:
*and the .cgi should contain the BANNER URL
*a banner URL is the location of the banner..like:
*"http://bla.com/banner.gif"

========================================================

cgi-script that answer's this:
#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

print "Location: http://www.experts-exchange.com/v3.0/images/kpro-ad.gif\n\n";


other solution:
never change the image name but change the image when you need to change the picture. Leave it hosted on your server.


http://www.experts-exchange.com/v3.0/images/kpro-ad.gif\n\n";

Conclusion:
Ffor performance issues use:

http://perl.apache.org/guide/  
http://www.fastcgi.com/
0
 
LVL 5

Expert Comment

by:Peewee
ID: 7216672
nicce,
did you get the sloution you were looking for?

regards Peewee
0
 
LVL 5

Expert Comment

by:Peewee
ID: 7596406
nicce,

please clean up the status of this question


regards Peewee
0
 

Expert Comment

by:SpideyMod
ID: 8293069
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now