Home: Perl Programming Help: Beginner:
Web page stalls on: print "Location:mydomain\n\n"



MichaelBluejay
New User

Feb 2, 2013, 12:57 PM


Views: 1351
Web page stalls on: print "Location:mydomain\n\n"

This works fine:

Quote
#! /usr/bin/perl
print "Location:http://AnyDomainBesidesMyOwn.com/\n\n";
close(STDOUT); close(STDIN); close(STDERR);
[some long process]


But the following way stalls the browser, refusing to redirect until the long process is finished:

Quote
#! /usr/bin/perl
print "Location:http://MyOwnDomain.com/\n\n";
close(STDOUT); close(STDIN); close(STDERR);
[some long process]


The long process can be simulated with: sleep 10;

What the hell?


wickedxter
User

Feb 2, 2013, 4:21 PM


Views: 1347
Re: [MichaelBluejay] Web page stalls on: print "Location:mydomain\n\n"

is script being run by a web server? what web server is on the other end?


MichaelBluejay
New User

Feb 2, 2013, 4:36 PM


Views: 1345
Re: [MichaelBluejay] Web page stalls on: print "Location:mydomain\n\n"

Yes, it's being run on my Apache web server.


FishMonger
Veteran / Moderator

Feb 3, 2013, 8:58 AM


Views: 1332
Re: [MichaelBluejay] Web page stalls on: print "Location:mydomain\n\n"

If you plan on doing additional processing after a redirect, then you need to fork, which you are not doing in the code you posted.


MichaelBluejay
New User

Feb 3, 2013, 10:15 AM


Views: 1328
Re: [MichaelBluejay] Web page stalls on: print "Location:mydomain\n\n"

(1) Why is it necessary to fork?

(2) The code works fine if I redirect to another domain, just not to my own domain. Should I be forking when redirecting to another domain too, even though it appears to work perfectly without forking?

(3) Does the fact that redirects to another domain work fine suggest that the problem with redirecting within my domain is not a forking problem, but rather something else?

(4) I looked up forking and tried the following code, and now the redirect happens right away, but the forked code doesn't execute (i.e., the file is not created).


Quote
#! /usr/bin/perl

if ($pid = fork) { }
else {
close STDOUT();
open(FILE,'>test.txt');
print FILE time;
close(FILE);
exit(0);
}
print "Location: http://mydomain.com/\n\n";



MichaelBluejay
New User

Feb 4, 2013, 5:58 PM


Views: 1306
Re: [MichaelBluejay] Web page stalls on: print "Location:mydomain\n\n"

Okay, I can get fork to work if I change STDOUT() to (STDOUT). (Whoops.)

I'm still wondering why I have to fork in the first place. Works fine when I redirect to a different domain. Any ideas?