GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Optimized redirection (cgi/perl) (https://gfy.com/showthread.php?t=69220)

HQ 07-24-2002 09:10 AM

Optimized redirection (cgi/perl)
 
Here's a simple redirection perl script:

Code:

#!/usr/bin/perl -wT
print "Location:http://www.nba.com/\n\n ";
sleep(15);
exit;

If you run it, you will notice that it waits 15 seconds before going to nba.com, even though nothing else is required to be 'printed' to the browser. The sleep is stuck in there to represent tracker calculations that have to be perform.

Is there anyway to cause the redirect to take place immediately, and then perform the calculations afterwards?

Babaganoosh 07-24-2002 09:35 AM

Not efficiently. The only way I can think of to do something like that is to fork() a process off and do the calculations there, but I absolutely would not do that unless it is absolutely necessary. Hopefully though, your code is smooth enough to do the calculations before the user is forwarded. Simple mathematic calculations should be carried out in a fraction of a second. The user shouldn't get impatient and close the browser in that .10 of a second.

mike503 07-24-2002 12:44 PM

uh yeah. you should be able to do all the processing before and then fire off the location header..

if you're doing that complicated of processding you may need to move to either real-time analysis (not real-time calculation) or go with a batch approach (i.e. cronjob every x minutes.)

NetRodent 07-24-2002 05:04 PM

Try using the following code...

Code:

#!/usr/bin/perl -wT
$| = 1;
print "Location:http://www.nba.com/\n\n ";
sleep(15);
exit;

The $| variable controls how perl buffers output. Setting
it to 1 tells it not to buffer anything but output immediately.
In general its a bad idea not to buffer but this will redirect
immediately.

[Labret] 07-24-2002 05:10 PM

You randomization layers are too low.

Add a couple of glitch targeting mechanisms in order to better bedunktify the layering effect caused by the circumpreferential treatment of African Americans. fo shizzy.

Phil21 07-24-2002 06:58 PM

what netrodent said should work well.

-Phil

HQ 07-25-2002 11:45 AM

Labert, what?

NetRodent, cool i'll try that. When the script in question is only going to output a redirect (one line of text), then 'turning off' the buffer should not be a problem. Damn, I never knew there was a buffer, this is why I was confused by the waiting.

mik503, I do batch processing. I'm creating a tracker which logs raw data and it gets processed every update of the site. However, sending hits out and tracking hits in has to be accomplished in real time. The only calculations are updates to these real-time tables that stores url info, hits in, hits out, clicks produced, and where every IP has gone so I don't send it back to the same place twice. The calculations should be quick, but some of these are calculations that can be performed AFTER the destination is known (for permanent links). For blind links, the calcuations have to be performed beforehand.

Armed & Hammered, I thought of performing a fork too, but NetRodent's idea is the best solution I think.

Thanks all.

HQ 07-25-2002 11:47 AM

Quote:

Originally posted by NetRodent
The $| variable controls how perl buffers output. Setting
it to 1 tells it not to buffer anything but output immediately.
In general its a bad idea not to buffer but this will redirect
immediately.

One question. Does the $| variable change the buffer of outputs to files too? As my redirect script will be modifying files (which means it will be outputing their full contents).

NetRodent 07-25-2002 01:31 PM

Here's what the perl documentation has to say about the $| variable at http://www.perldoc.com/perl5.6/pod/perlvar.html

Quote:

autoflush HANDLE EXPR
$OUTPUT_AUTOFLUSH
$|
If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See perlfunc/getc for that. (Mnemonic: when you want your pipes to be piping hot.)
So to answer your question, setting the $| changes the buffering on all output including files. Of course you can do something like
this:

Code:

#!/usr/bin/perl -wT
$| = 1; # unbuffer this
print "Location:http://www.nba.com/\n\n ";
$| = 0; # buffer everything else
open(LOG, ">>log");
print LOG "blah blah blah\n";
close LOG;
exit;

It also appears that you may be able to set the buffering on particular output channels. Try reading the perl IO faqhere.

HQ 07-25-2002 03:13 PM

$|=1; made the redirection work faster but it was messing up my file writing (I did a $|=0; right after the redirect). Very strange. No scripting errors or anything, just that the file wasn't being written to where it was before.


All times are GMT -7. The time now is 06:39 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123