I am using Mojilicious Lite.
#!/usr/bin/perl -T
use strict;
use Mojolicious::Lite;
get '/' => 'index';
# Run the Mojolicious script in CGI mode.
app->start;
#template
__DATA__
## index.html.ep
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>
<body>
pass 15
</body>
</html>
All is working fine but I have an intermittent issue,some times I get error page which says:
"Page not found... yet!
None of these routes could generate a response for your GET request for /, maybe you need to add a new one?"
This happen very rarely (1 out of 20 hit).
Can anyone please let me know what is the issue and how can I overcome of it?
Thanks in advance..
My Error Log is:
[Tue May 26 18:12:42 2015] [debug] GET "/".
[Tue May 26 18:12:42 2015] [debug] Routing to a callback.
[Tue May 26 18:12:42 2015] [debug] Template "index.html.ep" not found.
[Tue May 26 18:12:42 2015] [debug] Template "not_found.development.html.ep" not found.
[Tue May 26 18:12:42 2015] [debug] Template "not_found.html.ep" not found.
[Tue May 26 18:12:42 2015] [debug] Rendering inline template "3e3201ab0667c1fc7f39089209f0435c".
[Tue May 26 18:12:42 2015] [debug] Rendering inline template "b2d451b47e2053ce583cbfdf7bcc6006".
Finally I find that this is a bug with mojilicious light(while rendering inline templetes).
bug report 1
bug report 2
I resolved my problem by using external templates
Example:
My application file:
#!/usr/bin/perl -T
use strict;
use Mojolicious::Lite;
get '/' => 'index';
# Run the Mojolicious script in CGI mode.
app->start;
and my template file with name index.html.ep
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>
<body>
pass 15
</body>
</html>
Note: We have to define this file in templates directory .
Related
Why does WWW::Mechanize have blank content after getting the following URL? Using a browser or curl there is a full HTML page retrieved.
use WWW::Mechanize;
$mech = new WWW::Mechanize;
$mech->get("http://www.belizejudiciary.org/web/judgements2/");
print $mech->content # prints nothing
Here is the dump of the response:
HTTP/1.1 200 OK
Connection: close
Date: Fri, 10 Feb 2017 00:51:47 GMT
Server: Apache/2.4
Content-Type: text/html; charset=UTF-8
Client-Aborted: die
Client-Date: Fri, 10 Feb 2017 00:51:48 GMT
Client-Peer: 98.129.229.64:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Link: <http://www.belizejudiciary.org/web/wp-json/>; rel="https://api.w.org/"
Link: <http://www.belizejudiciary.org/web/?p=468>; rel=shortlink
Set-Cookie: X-Mapping-hepadkon=FAB86566672CEB74D66B2818CA030616; path=/
X-Died: Illegal field name 'X-Meta-Twitter:title' at /usr/local/lib/perl5/site_perl/5.16.3/sun4-solaris/HTML/HeadParser.pm line 207.
X-Pingback: http://www.belizejudiciary.org/web/xmlrpc.php
I have version 3.70 of HTML::Parser installed.
Your dump shows that there was an error parsing the response:
X-Died: Illegal field name 'X-Meta-Twitter:title' at /usr/local/lib/perl5/site_perl/5.16.3/sun4-solaris/HTML/HeadParser.pm line 207.
This is caused by a bug in HTML::HeadParser:
<meta> tags can have name attributes with colons in them, and this is perfectly valid. But HTML::HeadParser then tries to register these as X-Meta-<name> headers using HTTP::Headers. Newer versions of HTTP::Headers (since 6.05) have stricter checks for headers, and will refuse them if they contain colons.
This was fixed in version 3.71 of the HTML-Parser distribution, so you should upgrade.
I have this very simple Mojolicious Lite script:
#!/usr/bin/env perl
use v5.10;
use WWW::Mechanize::PhantomJS;
use Mojolicious::Lite;
my $mech = WWW::Mechanize::PhantomJS->new();
$mech->get('http://stackoverflow.com/');
get '/test' => sub {
my $c = shift;
$mech->get("https://stackoverflow.com/questions");
$c->render(template => 'activity');
};
app->secrets(['test secret']);
app->start;
__DATA__
## activity.html.ep
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body><h2>Test</h2></body>
</html>
When I start it using hypnotoad in foreground mode (hypnotoad -f ./script.pl), and access /test url -- I get my test page, and clean logs:
[Fri Dec 11 18:00:23 2015] [info] Listening at "http://*:8080"
[Fri Dec 11 18:00:23 2015] [info] Manager 3011 started
[Fri Dec 11 18:00:23 2015] [info] Creating process id file "/home/username/pc_activity/demo_site/hypnotoad.pid"
When I start it using background mode (hypnotoad ./script.pl), and access /test url -- I get "something went very wrong" error page with throwing up raptor.
[Fri Dec 11 17:58:07 2015] [info] Listening at "http://*:8080"
[Fri Dec 11 17:58:07 2015] [info] Manager 2964 started
[Fri Dec 11 17:58:07 2015] [info] Creating process id file "/home/username/pc_activity/demo_site/hypnotoad.pid"
[Fri Dec 11 17:58:14 2015] [error] Error while executing command: get: Server returned error message Can't connect to localhost:8910
Connection refused at /usr/local/share/perl/5.18.2/LWP/Protocol/http.pm line 47, <DATA> line 49.
instead of data at /usr/local/share/perl/5.18.2/Selenium/Remote/Driver.pm line 310.
It turns out the localhost:8910 is default settings for PhanomJS to run at in webdriver mode. Which it isn't on my machine. But even if I start it, and then access the URL, I still get an error:
[Fri Dec 11 18:41:01 2015] [error] Error while executing command: get: Server returned error message Variable Resource Not Found - {"headers":{"Accept":"application/json","Connection":"TE, close","Content-Length":"45","Content-Type":"application/json; charset=utf-8","Host":"localhost:8910","TE":"deflate,gzip;q=0.3","User-Agent":"libwww-perl/6.15"},"httpVersion":"1.1","method":"POST","post":"{\"url\":\"https://stackoverflow.com/questions\"}","url":"/session/98799e80-a060-11e5-8907-0b365878087d/url","urlParsed":{"anchor":"","query":"","file":"url","directory":"/session/98799e80-a060-11e5-8907-0b365878087d/","path":"/session/98799e80-a060-11e5-8907-0b365878087d/url","relative":"/session/98799e80-a060-11e5-8907-0b365878087d/url","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/session/98799e80-a060-11e5-8907-0b365878087d/url","queryKey":{},"chunks":["session","98799e80-a060-11e5-8907-0b365878087d","url"]}} instead of data at /usr/local/share/perl/5.18.2/Selenium/Remote/Driver.pm line 310.
I guess, I don't understand, why does it run in foreground mode, and not in background mode. And then, what can I do to make it run in background mode?
The reason it will not run in background mode is because of threading. After you start hypnotoad in background it spawns some processes.
664161507 46028 1 0 10:34AM ?? 0:00.01 script.pl
664161507 46029 46028 0 10:34AM ?? 0:00.08 script.pl
664161507 46030 46028 0 10:34AM ?? 0:00.01 script.pl
664161507 46031 46028 0 10:34AM ?? 0:00.01 script.pl
664161507 46032 46028 0 10:34AM ?? 0:00.01 script.pl
These will not have access to the PhantomJS you created in the parent process. I didn't look into how this communication is done, but if you want to share PhantomJS for your workers you need to make it a separate service.
If you however want to have a PhantomJS for each request you can initialize it in the request, but I don't necessarily encourage this approach:
get '/test' => sub {
my $c = shift;
my $mech = WWW::Mechanize::PhantomJS->new();
$mech->get('http://stackoverflow.com/');
$mech->get("https://stackoverflow.com/questions");
$c->render(template => 'activity');
};
I think its a simple path issue here - but I've spent last 2 hours trying various combinations but not able to resolve this. The code is working fine on my windows system but when I upload it to my hosting site on linux OS - it doesn't find the ACL file.
This is how the paths are defined in my index.php
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), get_include_path(),
)));
This is the line in application.ini
resources.frontController.plugins.acl = "Ed_Controller_Plugin_Acl"
This is the bootstrap.php relevant code
protected function _initAutoload()
{
.......
Zend_Loader_Autoloader::getInstance()->registerNamespace('Ed_');
.......
}
These are the errors I am getting on the linux system and the ACL doesn't work
[Sat Oct 01 14:26:44 2011] [error] [client 122.164.175.204] PHP Warning: include_once(Ed/Controller/Plugin/Acl.php): failed to open stream: No such file or directory in /home/webadmin/dezyre.com/library/Zend/Loader.php on line 146
[Sat Oct 01 14:26:44 2011] [error] [client 122.164.175.204] PHP Warning: include_once(): Failed opening 'Ed/Controller/Plugin/Acl.php' for inclusion (include_path='/home/webadmin/dezyre.com/application/../library:/home/webadmin/dezyre.com/library:.:/usr/share/pear:/usr/share/php') in /home/webadmin/dezyre.com/library/Zend/Loader.php on line 146
[Sat Oct 01 14:26:44 2011] [error] [client 122.164.175.204] PHP Fatal error: Class 'Ed_Controller_Plugin_Acl' not found in /home/webadmin/dezyre.com/library/Zend/Application/Resource/Frontcontroller.php on line 117
Thanks for your time
Appreciate it
Remember that *ix is all case sensitive with file names. Therefore directories must start with in uppercase. If they don't, Windows won't complain - but Linux will.
I am getting some very annoying behaviour from my perl cgi scripts running under apache.
I get referer information added on the end of simple print statements, and it's driving me nuts.
[Sun Feb 20 21:34:47 2011] [error] [client xx] ruid: 48, referer: http://www.x.com/
[Sun Feb 20 21:34:47 2011] [error] [client xx] euid: 48, referer: http://www.x.com/
[Sun Feb 20 21:34:47 2011] [error] [client xx] test, referer: http://www.x.com/
[Sun Feb 20 21:34:47 2011] [error] [client xx] Premature end of script headers: test.cgi, referer: http://www.x.com/
This only seems to happen when the url is reached by navigating from another page (hence having a referer yes). The above apache log output was produced with the below incredibly simple depo script:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
my $q = CGI->new;
print STDERR "ruid: $<\n";
print STDERR "euid: $>\n";
print STDERR "test\n";
Anyone seen this before? It feels like an apache setting i need to turn off.
Thanks
Matt
Take a look at your apache config files (httpd.conf and friends) and find the CustomLog directive which is used by your error log to see which LogFormat it uses, then modify that LogFormat (or create a new one) to remove %{Referer} from the list of fields to include in the log messages. (And don't forget to reload the apache config after changing it, of course.)
I am new to CGI-Perl and sessions. I have a problem running the following code.
I have four files
1. Session.html or Session.pm
2. name.pl
3. hobbies.pl
4. job.pl
The Session.pm is place in /var/www/html folder and the rest of the files are placed in /var/www/cgi-bin/session folder.
I have a basic html file(Session.html) which has a link to perl script it is giving the following error
[Mon Jan 04 14:21:24 2010] [error] [client ::1] Options ExecCGI is off in this directory: /var/www/html/name.pl, referer: http://localhost/Session.html
[Mon Jan 04 14:21:29 2010] [error] [client ::1] Options ExecCGI is off in this directory: /var/www/html/name.pl, referer: http://localhost/Session.html
[Mon Jan 04 14:22:42 2010] [error] [client ::1] (13)Permission denied: exec of '/var/www/cgi-bin/session/name.pl' failed, referer: http://localhost/Session.pm
[Mon Jan 04 14:22:42 2010] [error] [client ::1] Premature end of script headers: name.pl, referer: http://localhost/Session.pm
Please help me out in executing the above example. Please give me the steps to be followed from the start.
... Options ExecCGI is off in this directory: /var/www/html/name.pl, ...
This error points to trying to run name.pl in /var/www/html/ instead of /var/www/cgi-bin/session/
Is the Session.html you posted correct because it doesn't seem to tally with this error?
... (13)Permission denied: exec of '/var/www/cgi-bin/session/name.pl' failed, ...
The name.pl cannot be run because it doesn't have execution rights set (on Linux/Unix you need to chmod a+x name.pl).
You may need to show what Session.pm does (it doesn't look like you using the CPAN module Session here).
On a general note I would consider simplifying what you doing down to a simple HTML & CGI script first and get that working. Then start looking into sessions etc.
Check out Ovid's CGI Tutorial for some sage advice on the Perl/CGI subject.
/I3az/