1Mojolicious::Guides::FAUQs(e3r)Contributed Perl DocumentMaotjioolnicious::Guides::FAQ(3)
2
3
4

NAME

6       Mojolicious::Guides::FAQ - Frequently Asked Questions
7

OVERVIEW

9       This document contains answers for the most frequently asked questions
10       about Mojolicious.
11

QUESTIONS

13       We hope these answers are to your satisfaction.
14
15   How does Mojolicious compare to other Perl web frameworks?
16       The short answer is "it doesn't", because we interpret the term "web
17       framework" much more literally than others. With the emergence of the
18       real-time web and new technologies such as WebSockets, we are facing
19       new challenges that go way beyond what commonly used modules like LWP
20       were designed for. Because of this, Mojolicious contains a whole new
21       HTTP client/server stack called Mojo, which was heavily inspired by the
22       original LWPng effort and carefully designed with these new
23       requirements in mind. So while some of the higher abstraction layers
24       might look similar to other web frameworks, it is more of a web toolkit
25       and can even be used as the foundation for more advanced web
26       frameworks.
27
28   Why doesn't Mojolicious have any dependencies?
29       We are optimizing Mojolicious for user-friendliness and development
30       speed, without compromises. While there are no rules in
31       Mojolicious::Guides::Contributing that forbid dependencies, we do
32       currently discourage adding non-optional ones in favor of a faster and
33       more painless installation process. And we do in fact already use
34       several optional CPAN modules such as Cpanel::JSON::XS, EV,
35       IO::Socket::Socks, IO::Socket::SSL, Net::DNS::Native, Plack and
36       Role::Tiny to provide advanced functionality if possible.
37
38   Why reinvent wheels?
39       Because we can make them rounder. Components specifically designed for
40       user-friendliness and development speed are not easy to come by. We are
41       strong believers of the Perl mantra "There is more than one way to do
42       it", and our quest is to develop the best possible solutions for these
43       two criteria.
44
45   What about backwards compatibility?
46       In conformance with Mojolicious::Guides::Contributing, we will always
47       deprecate a feature for 3 months, before removing or changing it in
48       incompatible ways between major releases. New features can however be
49       marked as experimental to explicitly exclude them from these rules.
50       This gives us the necessary freedom to ensure a healthy future for
51       Mojolicious. So, as long as you are not using anything marked
52       experimental, untested or undocumented, you can always count on
53       backwards compatibility, everything else would be considered a bug.
54       However, to completely avoid any risk of accidental breakage, we do
55       recommend following current best practices for version pinning with
56       Carton for production setups.
57
58   Why not split up Mojolicious into many smaller distributions?
59       Because there are no advantages, it drastically increases maintenance
60       costs and installation times without giving us anything in return. It
61       would only make sense if we wanted to pass ownership of a module to a
62       new maintainer, which we already have done in the past.
63
64   Where can i discuss my patches for Mojolicious?
65       We'd love to discuss your contributions to Mojolicious on our official
66       IRC channel "#mojo" on "irc.freenode.net" (chat now!
67       <https://kiwiirc.com/nextclient/#irc://irc.freenode.net/mojo?nick=guest-?>).
68
69   Which versions of Perl are supported by Mojolicious?
70       First of all, you need to be aware that according to the perlpolicy,
71       only the two most recent stable release series of Perl are supported by
72       the community and receive bug fixes, which are currently 5.28.x and
73       5.26.x.  Mojolicious follows this model and fully supports these two
74       release series.  In addition we will also keep the distribution
75       installable (and that means passing all tests) up to a certain legacy
76       version that the core team deems worthy of supporting, but not
77       specifically optimize for it, this is currently 5.10.1.
78
79       Note that Perl versions 5.10.x and 5.12.x are known to work very poorly
80       with Mojolicious, and we strongly suggest you do not use them, to avoid
81       stability and security issues. If it wasn't for a very vocal minority
82       within the community we would not support these versions at all.
83
84   How well is Windows supported by Mojolicious?
85       Windows is not officially supported by Mojolicious, even though we try
86       to keep the distribution installable. There may be serious security
87       and/or reliability issues. Some of the more advanced features, such as
88       subprocesses and the Hypnotoad web server, will also require the use of
89       the Windows Subsystem for Linux
90       <https://msdn.microsoft.com/commandline/wsl/>.
91
92   Do I need to clean my environment before testing Mojolicious?
93       Mojolicious uses many environment variables both internally and
94       externally, notably (but not exclusively) those starting with the
95       prefix "MOJO_*" and "PLACK_ENV". The test suite expects a clean
96       environment; testing with a non-standard environment is unsupported and
97       is unlikely to succeed. Therefore when installing or upgrading
98       Mojolicious and when running its tests, we highly recommend using an
99       environment which does not set these variables.
100
101   Where did my file extension go?
102       Standard route placeholders will not match the "." character, however
103       Mojolicious routes automatically take file extensions like ".html",
104       remove the leading ".", and store the result in the "format" stash
105       value. This can be useful for URL-based content negotiation, such as
106       automatically rendering different templates based on the file
107       extension. See "Formats" in Mojolicious::Guides::Routing for
108       information on customizing format detection, or consider using relaxed
109       placeholders to allow matching of the "." character.
110
111   Can I configure Hypnotoad from the command line?
112       No, you can't, Hypnotoad is a bit special in this regard. Because when
113       you initiate a zero downtime software upgrade (hot deployment), you are
114       only really sending a "USR2" signal to the already running server, and
115       no other information can be passed along. What you can do instead, is
116       to use a Mojolicious::Plugin::Config or Mojolicious::Plugin::JSONConfig
117       configuration file.
118
119         # myapp.conf
120         {
121           hypnotoad => {
122             listen  => ['http://*:8080'],
123             workers => 10
124           }
125         };
126
127       Or if you don't actually need zero downtime software upgrades, just use
128       Mojolicious::Command::prefork instead, which is otherwise almost
129       identical to Hypnotoad.
130
131         $ ./myapp.pl prefork -m production -l http://*:8080 -w 10
132
133   What does the error "...certificate verify failed" mean?
134       There are many variations of this error, but most of them mean that TLS
135       certificate verification in Mojo::UserAgent failed. This usually
136       happens for two reasons. The most common one is that the peer
137       certificate is simply invalid.  If that's the case and you are certain
138       that no MITM attack is being attempted, you can use the attribute
139       "insecure" in Mojo::UserAgent or "MOJO_INSECURE" environment variable
140       to disable certificate verification. And if that's not the case you
141       might be missing the Mozilla::CA module, which is often required by
142       IO::Socket::SSL to be able to verify certificates.
143
144   What does the error "Maximum message size exceeded" mean?
145       To protect your applications from excessively large requests and
146       responses, our HTTP parser has a cap after which it will automatically
147       stop accepting new data, and in most cases force the connection to be
148       closed. The limit is 16MiB for requests, and 2GiB for responses by
149       default. You can use the attributes "max_request_size" in Mojolicious
150       and "max_response_size" in Mojo::UserAgent to change these values.
151
152   What does the error "Maximum start-line size exceeded" mean?
153       This is a very similar protection mechanism to the one described in the
154       previous answer, but a little more specific. It limits the maximum
155       length of the start-line for HTTP requests and responses. The limit is
156       8KiB by default, you can use the attribute "max_line_size" in
157       Mojo::Message or "MOJO_MAX_LINE_SIZE" environment variable to change
158       this value.
159
160   What does the error "Maximum header size exceeded" mean?
161       Almost the same as the previous answer, but this protection mechanism
162       limits the number and maximum length of HTTP request and response
163       headers. The limits are 100 headers with 8KiB each by default, you can
164       use the attributes "max_lines" in Mojo::Headers and "max_line_size" in
165       Mojo::Headers or the "MOJO_MAX_LINES" and "MOJO_MAX_LINE_SIZE"
166       environment variables to change these values.
167
168   What does the error "Maximum buffer size exceeded" mean?
169       This protection mechanism limits how much content the HTTP parser is
170       allowed to buffer when parsing chunked, compressed and multipart
171       messages. The limit is around 256KiB by default, you can use the
172       attribute "max_buffer_size" in Mojo::Content or "MOJO_MAX_BUFFER_SIZE"
173       environment variable to change this value.
174
175   What does "Your secret passphrase needs to be changed" mean?
176       Mojolicious uses secret passphrases for security features such as
177       signed cookies. It defaults to using "moniker" in Mojolicious, which is
178       not very secure, so we added this log message as a reminder. You can
179       change the passphrase with the attribute "secrets" in Mojolicious.
180       Since some plugins also depend on it, you should try changing it as
181       early as possible in your application.
182
183         $app->secrets(['My very secret passphrase.']);
184
185   What does "Nothing has been rendered, expecting delayed response" mean?
186       Mojolicious has been designed from the ground up for non-blocking I/O
187       and event loops. So when a new request comes in and no response is
188       generated right away, it will assume that this was intentional and
189       return control to the web server, which can then handle other requests
190       while waiting for events such as timers to finally generate a response.
191
192   What does "Inactivity timeout" mean?
193       To protect your applications from denial-of-service attacks, all
194       connections have an inactivity timeout which limits how long a
195       connection may be inactive before being closed automatically. It
196       defaults to 20 seconds for the user agent and 15 seconds for all built-
197       in web servers, and can be changed with the attributes
198       "inactivity_timeout" in Mojo::UserAgent and "inactivity_timeout" in
199       Mojo::Server::Daemon or the "MOJO_INACTIVITY_TIMEOUT" environment
200       variable. In Mojolicious applications you can also use the helper
201       "inactivity_timeout" in Mojolicious::Plugin::DefaultHelpers to change
202       it on demand for each connection individually. This timeout always
203       applies, so you might have to tweak it for applications that take a
204       long time to process a request.
205
206   What does "Premature connection close" mean?
207       This error message is often related to the one above, and means that
208       the web server closed the connection before the user agent could
209       receive the whole response or that the user agent got destroyed, which
210       forces all connections to be closed immediately.
211
212         # The variable $ua goes out of scope and gets destroyed too early
213         Mojo::IOLoop->timer(5 => sub {
214           my $ua = Mojo::UserAgent->new;
215           $ua->get('https://mojolicious.org' => sub {
216             my ($ua, $tx) = @_;
217             say $tx->result->dom->at('title')->text;
218           });
219         });
220
221   What does "Worker 31842 has no heartbeat (30 seconds), restarting" mean?
222       As long as they are accepting new connections, worker processes of all
223       built-in pre-forking web servers send heartbeat messages to the manager
224       process at regular intervals, to signal that they are still responsive.
225       A blocking operation such as an infinite loop in your application can
226       prevent this, and will force the affected worker to be restarted after
227       a timeout. This timeout defaults to 30 seconds and can be extended with
228       the attribute "heartbeat_timeout" in Mojo::Server::Prefork if your
229       application requires it.
230
231   What does "Transaction already destroyed" mean?
232       This error message usually appears after waiting for the results of a
233       non-blocking operation for longer periods of time, because the
234       underlying connection has been closed in the meantime and the value of
235       the attribute "tx" in Mojolicious::Controller is no longer available.
236       While there might not be a way to prevent the connection from getting
237       closed, you can try to avoid this error message by keeping a reference
238       to the transaction object that is not weakened.
239
240         # Keep a strong reference to the transaction object
241         my $tx = $c->render_later->tx;
242         $c->ua->get_p('https://mojolicious.org')->then(sub {
243           $c->render(text => 'Visited mojolicious.org');
244         })->catch(sub {
245           my $err = shift;
246           $tx;
247           $c->reply->exception($err);
248         });
249

MORE

251       You can continue with Mojolicious::Guides now or take a look at the
252       Mojolicious wiki <http://github.com/mojolicious/mojo/wiki>, which
253       contains a lot more documentation and examples by many different
254       authors.
255

SUPPORT

257       If you have any questions the documentation might not yet answer, don't
258       hesitate to ask on the mailing list
259       <http://groups.google.com/group/mojolicious> or the official IRC
260       channel "#mojo" on "irc.freenode.net" (chat now!
261       <https://kiwiirc.com/nextclient/#irc://irc.freenode.net/mojo?nick=guest-?>).
262
263
264
265perl v5.28.1                      2018-10-22       Mojolicious::Guides::FAQ(3)
Impressum