Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

script times out mysteriously

by Donboy (Initiate)
on Aug 27, 2003 at 04:45 UTC ( [id://286944]=perlquestion: print w/replies, xml ) Need Help??

Donboy has asked for the wisdom of the Perl Monks concerning the following question:

I just moved a bunch of Perl scripts over to a server that I control. First, all of my scripts now require the -w switch in order to run. Ok,ok, I know I SHOULD be running with it always, but I don't like all that clutter in my logs, so I'd like to know how I can turn off the -w switch and have the script still run. When I try without it, I get the dreaded 500 error, and the error log says "Premature end of script headers". Weird.

Second thing, some of my scripts will timeout before printing all the HTML. On this one particular script, I have a bunch of heredoc printing going on, like print <<EOF; and then another EOF later on. It generates most of the page, but the browser hangs before it prints everything. If I delete some of the HTML between the EOF's and reload the page, it will actually print everything except the stuff I removed. it's almost like the script is too big for it to handle.

URLs and log files can be provided on request.

Replies are listed 'Best First'.
Re: script times out mysteriously
by dws (Chancellor) on Aug 27, 2003 at 05:24 UTC
    I just moved a bunch of Perl scripts over to a server that I control. First, all of my scripts now require the -w switch in order to run. .. I'd like to know how I can turn off the -w switch and have the script still run.

    If you're FTPing the files from a Windows box to a *nix server in binary mode, carriage returns in the files are retained (ASCII mode removes the carriage returns). The effect of leaving carriage returns in the file is that the shebang line now reads

    #!/usr/bin/perl -w^M
    Depending on how you view the file, you might not see the ^M. With the -w there, this is O.K., but if you remove it and then FTP the file again, you'll get
    #!/usr/bin/perl^M
    which no longer names a valid executable file. You try to bring the file up through a web server, and you'll get a 500.

    Try FTPing in ascii mode.

      On a *nix box,

      vim -C file
      will show the ^M sequences.

      --Bob Niederman, http://bob-n.com

      All code given here is UNTESTED unless otherwise stated.

      I was FTPing from Unix to Unix in ASCII mode.
Re: script times out mysteriously
by bobn (Chaplain) on Aug 27, 2003 at 05:21 UTC

    I'd like to know how I can turn off the -w switch and have the script still run. When I try without it, I get the dreaded 500 error,

    The idea that removing -w causes a 500 error where there wasn't one before seems impossible. We would need logfiles and code snippets.

    URLs and log files can be provided on request.

    And code, please. We are not mind readers.

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.

Re: script times out mysteriously
by bean (Monk) on Aug 27, 2003 at 05:21 UTC
    How long it takes before your script times out is an Apache configuration issue. I believe the setting is "Timeout" - add an extra zero to the current setting and restart your server. You might consider timing sections of your code and optimizing whatever is slowing everything down.
    Update
    I just reread the question, and it implies that the slow section is just basically a big string. If that's true, I don't know why it would be so slow. I stand by the Apache config, however...
Re: script times out mysteriously
by CountZero (Bishop) on Aug 27, 2003 at 06:17 UTC

    On your second question: How long is the script, how big is it output and how long does it take for the script to run to conclusion? And equally important to know, what kind of server are you using (hardware + software specs)?

    I once ran into a similar issue with an Apache server: the script worked fine on our internal network and with most of our clients on the internet, but one client could not get it to run due to time-outs. It appeared that there was some "slow" link between them and us and this made the browser time out, requesting the script again (or perhaps they pressed the "reload" button), getting the heavy script to start again, until the server crawled to a halt and then a few minutes later (when the backlog cleared and all broken-off connections disappeared) the server ran fine again. Solution: split up the output over several webpages to be requested and send separately.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: script times out mysteriously
by asarih (Hermit) on Aug 27, 2003 at 05:39 UTC
    Besides what others have said already, you might want to look into the built-in variable $|. That might help with your timeout issues.
Re: script times out mysteriously
by Anonymous Monk on Aug 27, 2003 at 15:15 UTC
    Everyone, I'm still totally baffled, but I think I figured something out. It must have something to do with ownership or permissions.

    Up to this point, I have been editing the Perl scripts directly from the server using Samba. In other words, the server I'm running the scripts on is sitting in one room and I'm in another room editing the scripts from my Windows box.

    Well, just to test some of your suggestions today and gather information for a reply, I logged into the server using FTP. I downloaded the scripts, removed the -w switch, uploaded it again, and now everything works fine!

    If anyone can shed some light on WHY this happened, I'd be forever in your debt.

    Believe me, I'm not crazy. I was fiddling with this for hours last night trying to figure out why this was happening. I'm still stumped, but at least I've got a clue now.

      By the way, I checked ownership and permissions on those files before and after and they are the same as before. All files are chown donboy:donboy and chmod 755. This is one of the first things I checked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://286944]
Approved by weini
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found