Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Plack is "middleware" that sits between the web development framework (Catalyst/Dancer/etc) and the server. It smooths out the differences between, say, CGI, mod_perl, FastCGI, etc so that they can be deployed in all those different ways with little effort.

Plack-based websites can be deployed as CGI scripts. I have done this a number of times, and if you're careful you can get reasonable performance. However, if you use one of the larger frameworks like Catalyst, you'll find they run very slowly through CGI. This is because all the Perl modules used by the frameworks (in the case of Catalyst, this includes the Moose!) have to be loaded every request.

Other deployment options allow some or all code to "persist" between requests. For example, mod_perl keeps compiled (i.e. Perl optree) copies of all the modules your script uses in Apache's memory, saving them from being re-loaded and re-compiled each request.

Many deployment options do away with Apache or other "traditional" web servers altogether, instead using a web server written in pure Perl (or perhaps with a bit of XS to speed up the slow parts). Plack comes with the plackup tool which can be used to run many of these servers. If you've got the right permissions on the server you can write a shell script to start/stop the server and place it in /etc/init.d/ like all the other start/stop scripts on your machine that start/stop servers. Thus they'll restart when you restart the system.

Some people will power some parts of their website with Apache and other parts with a Perl web server running on a different TCP port; they can then use Apache's mod_proxy to forward certain requests to the Perl server.

If deploying via CGI or mod_perl, you certainly don't need root, and might not even need shell access.

If deploying via other means, you probably want shell access and maybe root access.

PS: here's an example of writing a tiny web app on bare Plack (no framework):

#!/usr/bin/env plackup # Assume this file is called "greeting.psgi" my $app = sub { return [ 200, [ Content_Type => 'text/plain' ], [ 'Hello world' ], ]; };

Just chmod +x greeting.psgi to mark it as executable, then run it at the command line. It will spawn a Perl web server on port 5000 of your computer. Type "http://localhost:5000/" into your your browser and lo and behold, a friendly greeting to the planet!

If you want to deploy it on CGI, create an accompanying file called greeting.cgi containing just:

#!/usr/bin/env perl use Plack::Loader; my $app = Plack::Util::load_psgi("/full/path/to/greeting.psgi"); Plack::Loader->auto->run($app);

... then chmod +x greeting.cgi, then visit the CGI script in your browser how you would normally.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

In reply to Re: Help me fill a gap in my server-side knowledge? by tobyink
in thread Help me fill a gap in my server-side knowledge? by Cody Fendant

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2018-06-20 04:35 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (116 votes). Check out past polls.