我有这个非常简单的 Mojolicious Lite 脚本:
#!/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>
当我在前台模式hypnotoad -f ./script.pl
(/test
[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"
当我使用后台模式hypnotoad ./script.pl
(/test
[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.
事实证明localhost:8910
,PhanomJS 是在 webdriver 模式下运行的默认设置。它不在我的机器上。但即使我启动它,然后访问 URL,我仍然会收到错误消息:
[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.
我想,我不明白,为什么它在前台模式下运行,而不是在后台模式下运行。然后,我该怎么做才能让它在后台模式下运行?