Apologies in advance for the tangential answer, but since I've done something very similar using Mojolicious I thought I'd show you how I did it there. I'll take a look at your code and see if I can figure out what's wrong with it in the meantime.

The controller:

package TailStream::Controller::Tail; use Mojo::Base 'Mojolicious::Controller'; use Mojo::Util qw(url_unescape); sub stream_tail { my $self = shift; my $encoded_filename = $self->stash('filename'); $self->inactivity_timeout(3600); my $filename = url_unescape $encoded_filename; die "Couldn't open $filename" unless -e -r -f $filename; my $pid = open my $fh, '-|', 'tail', '-n', '+1', '-F', $filename; die "Couldn't spawn: $!" unless defined $pid; my $stream = Mojo::IOLoop::Stream->new($fh); my $sid = Mojo::IOLoop->stream($stream); $self->on( finish => sub { Mojo::IOLoop->remove($sid) } ); $stream->on( read => sub { $self->send( { text => pop } ) } ); $stream->on( close => sub { kill KILL => $pid; close $fh } ); $stream->timeout(0); $stream->start; } 1;

And the application:

package TailStream; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; my $r = $self->routes; $r->websocket('/tail_ws/*filename')->to('tail#stream_tail'); } 1;

πάντων χρημάτων μέτρον έστιν άνθρωπος.


In reply to Re: tail file and websocket stream by jimpudar
in thread tail file and websocket stream by leostereo

Title:
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, details, 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, summary, 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.