FAQ
Sorry, bit of a newbie question: is there any way that I can run an action
but capture the results (server-side) to a file? Doing so client side is
easy (eg wget) but I want to keep the page text on the server and to
automate the page generation/save.

--
Regards,
Martin
(m.e@acm.org)
IT: http://methodsupport.com Personal: http://thereisnoend.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080623/51272c62/attachment.htm

Search Discussions

  • Octavian Rasnita at Jun 23, 2008 at 12:57 pm
    From: "Martin Ellison" <m.e@acm.org>
    Sorry, bit of a newbie question: is there any way that I can run an action
    but capture the results (server-side) to a file? Doing so client side is
    easy (eg wget) but I want to keep the page text on the server and to
    automate the page generation/save.
    You can run wget server side by a cron job and redirect the results wherever you want.

    Octavian
  • Kieren Diment at Jun 23, 2008 at 1:05 pm

    On 23 Jun 2008, at 21:45, Martin Ellison wrote:

    Sorry, bit of a newbie question: is there any way that I can run an
    action
    but capture the results (server-side) to a file? Doing so client
    side is
    easy (eg wget) but I want to keep the page text on the server and to
    automate the page generation/save.
    From Catalyst::View::TT:

    render($c, $template, \%args)

    Renders the given template and returns output, or a
    Template::Exception object upon error. ...

    so:

    my $var = $c->render($template, \%args);
    my $file = '/what/ever.html';
    print $FH, ">", $file;
  • Martin Ellison at Jun 23, 2008 at 5:11 pm
    ok, that works thanks (as does the server side wget).

    2008/6/23 Kieren Diment <diment@gmail.com>:
    On 23 Jun 2008, at 21:45, Martin Ellison wrote:

    Sorry, bit of a newbie question: is there any way that I can run an action
    but capture the results (server-side) to a file? Doing so client side is
    easy (eg wget) but I want to keep the page text on the server and to
    automate the page generation/save.
    From Catalyst::View::TT:

    render($c, $template, \%args)

    Renders the given template and returns output, or a Template::Exception
    object upon error. ...

    so:

    my $var = $c->render($template, \%args);
    my $file = '/what/ever.html';
    print $FH, ">", $file;


    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080624/d6169975/attachment.htm
  • Jonathan Rockway at Jun 23, 2008 at 3:42 pm

    * On Mon, Jun 23 2008, Martin Ellison wrote:
    Sorry, bit of a newbie question: is there any way that I can run an action but
    capture the results (server-side) to a file? Doing so client side is easy (eg
    wget) but I want to keep the page text on the server and to automate the page
    generation/save.
    If you want to log the output of every request, you probably want to
    wrap finalize and save the file after it runs.

    If you want to run an arbitrary request against your application and see
    the result, you want the Subrequest plugin. It would be better for your
    app to not depend upon your app, though. Calling a method is simpler,
    faster, and cleaner than running an entire request and capturing the
    result, so try to structure your app in such a way as to allow that.

    Regards,
    Jonathan Rockway

    --
    print just => another => perl => hacker => if $,=$"
  • Martin Ellison at Jun 23, 2008 at 5:23 pm
    I actually want to save a static copy of the front page to improve load
    times. My fastcgi process sometimes disappears (I'm on shared hosting and I
    think they auto-cancel stale processes), and it takes a while for the
    process to be restarted, which impacts the first page load. Subsequent pages
    are faster but it's the first page that makes the impression on the user.
    The static plugin does not work, because that requires fastcgi to be
    running, and my app is too small for me to set up squid.

    So I want to redirect the front page to a static page, but regenerate the
    static page, and also force the app to do something (so the server can
    restart the fastcgi process before the user requests any other page).

    2008/6/23 Jonathan Rockway <jon@jrock.us>:
    * On Mon, Jun 23 2008, Martin Ellison wrote:
    Sorry, bit of a newbie question: is there any way that I can run an
    action but
    capture the results (server-side) to a file? Doing so client side is easy (eg
    wget) but I want to keep the page text on the server and to automate the page
    generation/save.
    If you want to log the output of every request, you probably want to
    wrap finalize and save the file after it runs.

    If you want to run an arbitrary request against your application and see
    the result, you want the Subrequest plugin. It would be better for your
    app to not depend upon your app, though. Calling a method is simpler,
    faster, and cleaner than running an entire request and capturing the
    result, so try to structure your app in such a way as to allow that.

    Regards,
    Jonathan Rockway

    --
    print just => another => perl => hacker => if $,=$"

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080624/146898d0/attachment.htm
  • Chisel Wright at Jun 23, 2008 at 5:36 pm

    On Tue, Jun 24, 2008 at 12:23:05AM +0800, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times. My fastcgi process sometimes disappears (I'm on shared hosting and
    Will setting the TTCACHE help at all?

    --
    Chisel Wright
    e: chisel@herlpacker.co.uk
    w: http://www.herlpacker.co.uk/

    Don't cha wish your boyfriend was geek like me?
  • Martin Ellison at Jun 23, 2008 at 5:54 pm
    As far as I know, the Template Toolkit only caches the compiled templates,
    not the output.

    2008/6/24 Chisel Wright <chisel@herlpacker.co.uk>:
    On Tue, Jun 24, 2008 at 12:23:05AM +0800, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times. My fastcgi process sometimes disappears (I'm on shared hosting
    and

    Will setting the TTCACHE help at all?

    --
    Chisel Wright
    e: chisel@herlpacker.co.uk
    w: http://www.herlpacker.co.uk/

    Don't cha wish your boyfriend was geek like me?

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/


    --
    Regards,
    Martin
    (m.e@acm.org)
    IT: http://methodsupport.com Personal: http://thereisnoend.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080624/e62deea9/attachment.htm
  • Matthias Zeichmann at Jun 23, 2008 at 6:10 pm

    On Mon, Jun 23, 2008 at 18:23, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times.
    did you look into
    http://search.cpan.org/dist/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
    ?

    you can use various backends with that (filecache, memcached, ...)
    --
    siggen.pl: Segmentation Fault
  • Bill Moseley at Jun 23, 2008 at 6:56 pm

    On Mon, Jun 23, 2008 at 07:10:31PM +0200, Matthias Zeichmann wrote:
    On Mon, Jun 23, 2008 at 18:23, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times.
    did you look into
    http://search.cpan.org/dist/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
    ?
    Or even:

    http://search.cpan.org/~agrundma/Catalyst-Plugin-PageCache-0.18/

    --
    Bill Moseley
    moseley@hank.org
    Sent from my iMutt
  • Ryan D Johnson at Jun 23, 2008 at 7:32 pm

    Bill Moseley writes:
    On Mon, Jun 23, 2008 at 07:10:31PM +0200, Matthias Zeichmann wrote:
    On Mon, Jun 23, 2008 at 18:23, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times.
    did you look into
    http://search.cpan.org/dist/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
    ?
    Or even:

    http://search.cpan.org/~agrundma/Catalyst-Plugin-PageCache-0.18/
    I doubt these plugins will help Martin since he's trying to fix the
    problem that his FCGI backend process has been torn down.

    On this subject though, PageCache is a really useful low-work
    high-return way to do some simple page caching from Catalyst. It has
    built-in support for only caching unauth'd pages, caches based on
    wildcards, all kinds of useful stuff.

    But there is one caveat I ran into when playing with it. If you're doing
    Content-Encoding negotiation in Catalyst (with C::P::Compress::Gzip, for
    example), the PageCache doesn't know about it and will cache either the
    gzip'd or plain version depending on which is first hit, then serve that
    out indiscriminately to all clients.

    As an example, hit a cachable page with your web browser (which supports gzip),
    then try to fetch the same (cached) page with curl or something; you'll
    get the gzip'd stream of gibberish.

    If you're doing Content-Encoding negotiation in your webserver, which is
    probably better (and with a patch or 1.5 trunk lighttpd now supports
    this with mod_deflate), you don't have to worry about this.

    I've been mulling over whether there's any reasonable way to fix things
    to deal with this, but it amounts to any kind of content negotiation
    needing to run very early (as part of dispatch?) and somehow publishing
    that information to the rest of the pipeline. In the case of PageCache,
    it would simply need to incorporate any negotiated content information
    into the cache key. This sort of runs the whole gamut from Accept,
    Accept-Language, Accept-Encoding, etc.

    If negotiations required explicit controller code, you could make the
    case that we should just augment cache_page to accept some kind of cache
    key seed so that the controller could run some very minimal code, then
    call cache_page with like seed => 'json' or whatever. Unfortunately,
    people like their negotiation code to be transparent, like the
    compression or the cool auto-negotiation that the REST stuff does (which
    IIRC will output json, xml, yaml, whatever transparently to the
    controller code).

    /rdj
  • Aristotle Pagaltzis at Jun 23, 2008 at 9:37 pm

    * Ryan D Johnson [2008-06-23 20:40]:
    I've been mulling over whether there's any reasonable way to
    fix things to deal with this, but it amounts to any kind of
    content negotiation needing to run very early (as part of
    dispatch?) and somehow publishing that information to the rest
    of the pipeline.
    Yes, http://tools.ietf.org/html/rfc2616#section-14.44

    HTTP. If you are a web app developer, it is your job to learn it,
    love it, live it, breathe it. At the very least, study RFC?2616
    once to know what?s in there. Most people who try to ?solve? some
    problem with their web app architecture a) do so because they are
    ignorant of all the facilities of HTTP and b) end up inventing a
    worse wheel than what HTTP itself provides. The simplicity of
    HTTP is deceptive; it conceals the deep deliberation that went
    into choosing *this* form of simplicity vs some other one.

    (Oh, and this is not a personal comment to you, Ryan ? I mean the
    ?you?s above in the general sense.)

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Ryan D Johnson at Jun 23, 2008 at 10:04 pm

    Aristotle Pagaltzis writes:

    * Ryan D Johnson [2008-06-23 20:40]:
    I've been mulling over whether there's any reasonable way to
    fix things to deal with this, but it amounts to any kind of
    content negotiation needing to run very early (as part of
    dispatch?) and somehow publishing that information to the rest
    of the pipeline.
    HTTP.
    I'm not 100% sure if I followed your point. I think it was well-behaved
    servers should be setting the Vary response header when content is
    negotiated based on a request header, and well-behaved caches should pay
    attention to it.

    Here's where I show ignorance of the Catalyst plugin model. For example,
    C::P::PageCache and C::P::Compress::Gzip both hook into finalize --
    PageCache to cache the data, Gzip to compress the data. Is the calling
    order for those two guaranteed somehow by NEXT? If I include PageCache
    *last* (or *first*?) in the plugin load order, will that guarantee that
    all the other plugins have done their work?

    If so, it might make sense for PageCache to pay attention to the Vary
    header. I imagine that the cache save and lookup code will get
    significantly more complex, though.

    /rdj
  • Aristotle Pagaltzis at Jun 23, 2008 at 11:40 pm

    * Ryan D Johnson [2008-06-23 23:10]:
    Here's where I show ignorance of the Catalyst plugin model. For
    example, C::P::PageCache and C::P::Compress::Gzip both hook
    into finalize -- PageCache to cache the data, Gzip to compress
    the data. Is the calling order for those two guaranteed somehow
    by NEXT?
    Indeed it is.
    If I include PageCache *last* (or *first*?) in the plugin load
    order, will that guarantee that all the other plugins have done
    their work?
    The CP::PageCache POD says ?PageCache should be placed at the end
    of your plugin list? ? probably for a reason. :-)
    If so, it might make sense for PageCache to pay attention to
    the Vary header. I imagine that the cache save and lookup code
    will get significantly more complex, though.
    Not a whole lot ? it needs to incorporate those request headers
    into a compound key.

    Parsing the Vary header isn?t very hard either.

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Ryan D Johnson at Jun 24, 2008 at 12:03 am

    On Mon, Jun 23, 2008 at 3:40 PM, Aristotle Pagaltzis wrote:

    If so, it might make sense for PageCache to pay attention to
    the Vary header. I imagine that the cache save and lookup code
    will get significantly more complex, though.
    Not a whole lot � it needs to incorporate those request headers
    into a compound key.

    I was thinking more of the lookup than the storage. Perhaps it's as
    straightforward as associating a set of headers with a given URI so that you
    can remember which ones need to be used to generate the lookup key. But what
    if two responses for the same URI yield a different Vary header? Etc. It's
    starting to sound more like search than lookup.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080623/d2ccd70c/attachment.htm
  • Jonathan Rockway at Jun 24, 2008 at 12:08 pm

    * On Mon, Jun 23 2008, Ryan D Johnson wrote:
    On this subject though, PageCache is a really useful low-work
    high-return way to do some simple page caching from Catalyst. It has
    built-in support for only caching unauth'd pages, caches based on
    wildcards, all kinds of useful stuff.

    But there is one caveat I ran into when playing with it. If you're doing
    Content-Encoding negotiation in Catalyst (with C::P::Compress::Gzip, for
    example), the PageCache doesn't know about it and will cache either the
    gzip'd or plain version depending on which is first hit, then serve that
    out indiscriminately to all clients.

    As an example, hit a cachable page with your web browser (which supports gzip),
    then try to fetch the same (cached) page with curl or something; you'll
    get the gzip'd stream of gibberish.
    Use Angerwhale::Plugin::Cache instead. It solves this problem.

    Regards,
    Jonathan Rockway

    --
    print just => another => perl => hacker => if $,=$"
  • John Romkey at Jun 23, 2008 at 7:33 pm

    On Jun 23, 2008, at 1:56 PM, Bill Moseley wrote:
    On Mon, Jun 23, 2008 at 07:10:31PM +0200, Matthias Zeichmann wrote:
    On Mon, Jun 23, 2008 at 18:23, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve
    load
    times.
    did you look into
    http://search.cpan.org/dist/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
    ?
    Or even:

    http://search.cpan.org/~agrundma/Catalyst-Plugin-PageCache-0.18/
    Seconded. I've been using C:P:PageCache and it works very nicely.
    - john romkey
    http://www.romkey.com/
  • Brian Kirkbride at Jun 23, 2008 at 7:14 pm

    Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times. My fastcgi process sometimes disappears (I'm on shared hosting
    and I think they auto-cancel stale processes), and it takes a while for
    the process to be restarted, which impacts the first page load.
    Subsequent pages are faster but it's the first page that makes the
    impression on the user. The static plugin does not work, because that
    requires fastcgi to be running, and my app is too small for me to set up
    squid.

    So I want to redirect the front page to a static page, but regenerate
    the static page, and also force the app to do something (so the server
    can restart the fastcgi process before the user requests any other page).
    We do exactly this for our app and it's a lifesaver when hit with a
    Slashdotting. Our app is 99% read / 1% write so using a lightweight
    HTTP server (Lighttpd, NginX, etc) in front of the FastCGI Catalyst
    app makes for amazing scalability.

    To do this, we have something like this in our Root controller:

    sub render : ActionClass('RenderView') {}
    sub end : Private {
    my ( $self, $c ) = @_;

    $c->forward('render');
    if ($c->stash->{save_response_as}) {
    File::Slurp::write_file(
    $c->stash->{save_response_as},
    { atomic => 1, buf_ref => \$c->res->body }
    );
    }
    }

    Then you can use some -f style rules in apache or lighttpd to serve
    the file if it exists. On the (relatively) rare occasion of a write
    request we simple delete the files from the cache.

    Hope that helps!
    - Brian
  • Matt S Trout at Jul 20, 2008 at 12:36 am

    On Tue, Jun 24, 2008 at 12:23:05AM +0800, Martin Ellison wrote:
    I actually want to save a static copy of the front page to improve load
    times. My fastcgi process sometimes disappears (I'm on shared hosting and I
    think they auto-cancel stale processes), and it takes a while for the
    process to be restarted, which impacts the first page load. Subsequent pages
    are faster but it's the first page that makes the impression on the user.
    The static plugin does not work, because that requires fastcgi to be
    running, and my app is too small for me to set up squid.

    So I want to redirect the front page to a static page, but regenerate the
    static page, and also force the app to do something (so the server can
    restart the fastcgi process before the user requests any other page).
    Catalyst::Plugin::PageCache ?

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJun 23, '08 at 12:45p
activeJul 20, '08 at 12:36a
posts19
users12
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase