在Laravel 4路线上运行Artisan Command

时间:2014-09-12 15:33:00

标签: php laravel laravel-4 phantomjs

我在尝试在路线上运行工匠命令时遇到问题。

这是代码:

Route::get('/create_preview', function() {
    Artisan::call('cartero:run-phantomjs', array('url' => 'http://stackoverflow.com/'));
});

我的命令接受url作为参数,我使用PhantomJS从给定的网站创建截图。

在终端上运行正常,但我的浏览器呼叫路线没有任何反应。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

有了这个命令:

Usage:
 firewall:blacklist [--force] ip

Arguments:
 ip                    The IP address to be added.

Options:
 --force               Remove IP before adding it to the list.
 --help (-h)           Display this help message.
 --quiet (-q)          Do not output any message.
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version.
 --ansi                Force ANSI output.
 --no-ansi             Disable ANSI output.
 --no-interaction (-n) Do not ask any interactive question.
 --env                 The environment the command should run under.

这对我有用:

Artisan::call('firewall:blacklist', ['ip' => '10.10.10.10']);

你说but nothing happens from my browser calling the route.。没错,浏览器中没有显示任何内容,因为这是一个“仅命令行”命令,终端打印的字符串,回声等不会发送到Artisan :: call()中的浏览器,甚至不会发生错误。

答案 1 :(得分:0)

试试这个:

Artisan::call('cartero:run-phantomjs', array('--url' => 'http://stackoverflow.com/'));

答案 2 :(得分:0)

这是服务器中路径的问题,这是我的命令:

public function fire()
{
  $url = $this->argument('url');
  $filename = uniqid("sc");
  $path_phantomjs = base_path() . "/phantomjs/bin/phantomjs";
  $path_js = base_path() . "/screen.js";
  $path_dest = base_path() . "/public/uploads/previews/".$filename.".png";
  return exec($path_phantomjs . " " .$path_js . " " . $url . " " .$path_dest);
}

最初我没有使用帮助程序base_path(),并且在终端上运行良好但在浏览器中运行良好。我添加了一条路径并立即行动!!!!

相关问题