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

Hello, sry for my question. I have a problem loading perl cgi-bin script in apache2. Script is working when I start it from console, also is work from web too when I access it direct http://127.0.0.1/test.pl?run=true I see in apache logs access file, apache immediately receive request to start test.pl but it's took around 3 - 4 seconds until script start working. My question is: Do some body can tell me did I can avoid that delay ? I was using Devel::NYTProf trying to understand where thinks is slow down but no effect. Script started from console work like a charm Good day, HS

Replies are listed 'Best First'.
Re: Apache2 to perl slow start
by hippo (Archbishop) on Nov 12, 2019 at 12:31 UTC
    Do some body can tell me did I can avoid that delay ?

    First you need to find out where the delay is. How long does it take your apache to serve each of the following:

    1. An item of static content such as a small plain text file
    2. A bash CGI script which does nothing
    3. A perl CGI script which does nothing
    4. Your perl CGI script which does something

    If it's only item 4 which takes a long time, then the problem is with your script and you will need to debug it.

      Hello again,

      I run these test with simple test.cgi and apache server respond fast. I check again Devel::NYRProf trying to understand: Why when I start my script: run.pl from console start immediately the job with serial port and when I start it from apache cgi-bin have a delay around 3 sec.


      2 1 1 3.10s 3.10s IO::Socket::IP::CORE:sselect (opcode)
      406 1 1 2.86s 2.86s Device::SerialPort::CORE:sselect (opcode)

      199 3.11s line IO/Socket/IP.pm (including 1 string eval)
      16104 2.89s line Device/SerialPort.pm

      Well, I know it's a hard some one to guessing what can be the problem when there are also unknowns like modules that are loaded,
      but I was hopping for some hints or ideas how I can speed up a little the module.

      Thanks again
        I run these test with simple test.cgi and apache server respond fast.

        Good - so the problem is just with your script. Now, when you run the script from the shell and from the web server there are 3 main differences:

        • The user and group running the script
        • The environment
        • The context

        You can test out the first of these by running the script from the shell as the user and group who execute the Apache processes (eg. with sudo). For the environment your best plan is to dump it from within the script and compare these dumps from running in both ways - shell and web. Any differences there may well be relevant. Also dump %INC at the end while you are at it as you may find that there are different versions of modules being loaded which can otherwise be tricky to spot. Finally, to see if the context is affecting operations, check the audit log.

        You might also be interested to read through the Basic debugging checklist if you are not already familiar with it as there are some good practices and hints which may help.