Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Working towards PSGI, some questions

by Cody Fendant (Hermit)
on Jan 08, 2016 at 05:47 UTC ( [id://1152264]=perlquestion: print w/replies, xml ) Need Help??

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

As part of my new year resolutions, I'm converting a classic CGI app to PSGI.

So what I've done so far is:

  • installed plack
  • installed mod_perl
  • installed Plack::Handler::Apache2
  • written a minimal application
  • tweaked my Apache config to serve the application at a certain URL

and that's all working.

So ... what have I achieved exactly?

Is my tiny PSGI app somehow running within the apache process somewhere? Continually running in the webserver memory? If it is, how come I can change the code and see the changes without restarting Apache? If not, how come I can't see it as a process in top or whatever?

I feel I'm missing something here.

Replies are listed 'Best First'.
Re: Working towards PSGI, some questions
by Corion (Patriarch) on Jan 08, 2016 at 07:12 UTC

    Looking at Plack::Handler::Apache2, your app now runs under mod_perl.

    As I assume that your PSGI application is more or less a raw PSGI application, returning [200, {}, ["Hello World"]], maybe you have Apache set up to restart the httpd after each request, which is great for debugging.

    The easiest way to better confirm that your program is not run as a separate process would be some shared state between requests:

    my $counter= 1; warn "(Re)initializing application $0\n"; return sub { [200, {}, ["Hello request " . $counter++]] };

    If you cannot make $counter++ increase and constantly see the "(Re)initializing" message in your webserver error log, your webserver is running each request in a separate request.

    You should get really different behaviour by using plackup with (for example) the Twiggy, Tatsumaki or another in-process backend.

      Thanks, that was very helpful.

      The thing I'd missed was the instructions to preload the app, using a script:

      # Optionally preload your apps in startup PerlPostConfigRequire /etc/httpd/startup.pl

      As for going for another back end, that's a whole other thing I figure I'll get to next. All I know is Apache and a little bit of nginx, don't know where to start.

        I was and i'm still intersted in the topic: you may like to read Re: Change cgi script to PSGI app and Serving multiple Plack apps
        I also have other links on my homenode (..mmh that is a bit chaotic..)

        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        I usually use one of the other server types for development, as they make process control much easier to me.

        Running one of the other server types behind an Apache or nginx reverse proxy is also possible, but requires much more setup.

Re: Working towards PSGI, some questions
by u65 (Chaplain) on Jan 08, 2016 at 13:27 UTC

Log In?
Username:
Password:

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

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

    No recent polls found