从命令行运行Zend框架操作

时间:2022-10-10 14:53:31

I would like to run a Zend Framework action to generate some files, from command line. Is this possible and how much change would I need to make to my existing Web project that is using ZF?

我想运行一个Zend Framework操作,从命令行生成一些文件。这可能吗?我需要对使用ZF的现有Web项目做多少更改?

Thanks!

谢谢!

10 个解决方案

#1


60  

It's actually much easier than you might think. The bootstrap/application components and your existing configs can be reused with CLI scripts, while avoiding the MVC stack and unnecessary weight that is invoked in a HTTP request. This is one advantage to not using wget.

实际上比你想象的要简单得多。引导/应用程序组件和现有的配置可以与CLI脚本一起重用,同时避免在HTTP请求中调用MVC堆栈和不必要的权重。这是不使用wget的一个优点。

Start your script as your would your public index.php:

启动您的脚本,就像您的公共索引。php:

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH',
              realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));

require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/config.php'
);

//only load resources we need for script, in this case db and mail
$application->getBootstrap()->bootstrap(array('db', 'mail'));

You can then proceed to use ZF resources just as you would in an MVC application:

然后,您可以继续使用ZF资源,就像在MVC应用程序中那样:

$db = $application->getBootstrap()->getResource('db');

$row = $db->fetchRow('SELECT * FROM something');

If you wish to add configurable arguments to your CLI script, take a look at Zend_Console_Getopt

如果希望向CLI脚本添加可配置参数,请查看Zend_Console_Getopt

If you find that you have common code that you also call in MVC applications, look at wrapping it up in an object and calling that object's methods from both the MVC and the command line applications. This is general good practice.

如果您发现您有相同的代码,您也可以调用MVC应用程序,那么您可以将其封装到一个对象中,并从MVC和命令行应用程序中调用该对象的方法。这是一般的好习惯。

#2


63  

UPDATE

更新

You can have all this code adapted for ZF 1.12 from https://github.com/akond/zf-cli if you like.

While the solution #1 is ok, sometimes you want something more elaborate. Especially if you are expecting to have more than just one CLI script. If you allow me, I would propose another solution.

虽然解决方案#1是可行的,但有时您需要更精细的东西。特别是如果您希望拥有不止一个CLI脚本。如果你允许我,我将提出另一个解决办法。

First of all, have in your Bootstrap.php

首先,在Bootstrap.php中

protected function _initRouter ()
{
    if (PHP_SAPI == 'cli')
    {
        $this->bootstrap ('frontcontroller');
        $front = $this->getResource('frontcontroller');
        $front->setRouter (new Application_Router_Cli ());
        $front->setRequest (new Zend_Controller_Request_Simple ());
    }
}

This method will deprive dispatching control from default router in favour of our own router Application_Router_Cli.

此方法将从默认路由器中取消分派控制,而代之以我们自己的路由器Application_Router_Cli。

Incidentally, if you have defined your own routes in _initRoutes for your web interface, you would probably want to neutralize them when in command-line mode.

顺便说一下,如果您在web接口的_initpath中定义了自己的路由,您可能希望在使用命令行模式时消除它们。

protected function _initRoutes ()
{
    $router = Zend_Controller_Front::getInstance ()->getRouter ();
    if ($router instanceof Zend_Controller_Router_Rewrite)
    {
        // put your web-interface routes here, so they do not interfere
    }
}

Class Application_Router_Cli (I assume you have autoload switched on for Application prefix) may look like:

类Application_Router_Cli(我假设您已经为应用程序前缀打开了autoload)可能看起来如下:

class Application_Router_Cli extends Zend_Controller_Router_Abstract
{
    public function route (Zend_Controller_Request_Abstract $dispatcher)
    {
        $getopt = new Zend_Console_Getopt (array ());
        $arguments = $getopt->getRemainingArgs ();
        if ($arguments)
        {
            $command = array_shift ($arguments);
            if (! preg_match ('~\W~', $command))
            {
                $dispatcher->setControllerName ($command);
                $dispatcher->setActionName ('cli');
                unset ($_SERVER ['argv'] [1]);

                return $dispatcher;
            }

            echo "Invalid command.\n", exit;

        }

        echo "No command given.\n", exit;
    }


    public function assemble ($userParams, $name = null, $reset = false, $encode = true)
    {
        echo "Not implemented\n", exit;
    }
}

Now you can simply run your application by executing

现在,您可以通过执行来运行应用程序

php index.php backup

In this case cliAction method in BackupController controller will be called.

在这种情况下,将调用BackupController控制器中的cliAction方法。

class BackupController extends Zend_Controller_Action
{
    function cliAction ()
    {
        print "I'm here.\n";
    }
}

You can even go ahead and modify Application_Router_Cli class so that not "cli" action is taken every time, but something that user have chosen through an additional parameter.

您甚至可以继续修改Application_Router_Cli类,以便每次都不执行“cli”操作,而是用户通过附加参数选择的内容。

And one last thing. Define custom error handler for command-line interface so you won't be seeing any html code on your screen

最后一件事情。为命令行界面定义自定义错误处理程序,这样您就不会在屏幕上看到任何html代码

In Bootstrap.php

在Bootstrap.php

protected function _initError ()
{
    $error = $frontcontroller->getPlugin ('Zend_Controller_Plugin_ErrorHandler');
    $error->setErrorHandlerController ('index');

    if (PHP_SAPI == 'cli')
    {
        $error->setErrorHandlerController ('error');
        $error->setErrorHandlerAction ('cli');
    }
}

In ErrorController.php

在ErrorController.php

function cliAction ()
{
    $this->_helper->viewRenderer->setNoRender (true);

    foreach ($this->_getParam ('error_handler') as $error)
    {
        if ($error instanceof Exception)
        {
            print $error->getMessage () . "\n";
        }
    }
}

#3


7  

Just saw this one get tagged in my CP. If you stumbled onto this post and are using ZF2, it's gotten MUCH easier. Just edit your module.config.php's routes like so:

看到这个在我的CP中被标记了。如果你在这个帖子上被绊倒,并且正在使用ZF2,它会变得容易得多。编辑你的module.config。php的路线如下所示:

/**
 * Router
 */

'router' => array(
    'routes' => array(

        // .. these are your normal web routes, look further down
    ),
),

/**
 * Console Routes
 */
'console' => array(
    'router' => array(
        'routes' => array(

            /* Sample Route */
            'do-cli' => array(
                'options' => array(
                    'route'    => 'do cli',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'do-cli',
                    ),
                ),
            ),
        ),    
    ),
),

Using the config above, you would define doCliAction in your IndexController.php under your Application module. Running it is cake, from the command line:

使用上面的配置,您将在IndexController中定义doCliAction。在应用程序模块下的php。运行它是cake,从命令行:

php index.php do cli

php指数。cli php做

Done! Way smoother.

完成了!平滑方法。

#4


6  

akond's solution above is on the best track, but there are some subtleties that may may his script not work in your environment. Consider these tweaks to his answer:

akond的解决方案是在最好的轨道上,但是有一些微妙之处可能让他的脚本无法在你的环境中工作。考虑一下这些对他的回答的微调:

Bootstrap.php

Bootstrap.php

protected function _initRouter()
{
    if( PHP_SAPI == 'cli' )
    {
        $this->bootstrap( 'FrontController' );
        $front = $this->getResource( 'FrontController' );
        $front->setParam('disableOutputBuffering', true);
        $front->setRouter( new Application_Router_Cli() );
        $front->setRequest( new Zend_Controller_Request_Simple() );
    }
}

Init error would probably barf as written above, the error handler is probably not yet instantiated unless you've changed the default config.

Init错误可能会像上面所写的那样,barf,错误处理程序可能还没有实例化,除非您更改了默认配置。

protected function _initError ()
{
    $this->bootstrap( 'FrontController' );
    $front = $this->getResource( 'FrontController' );
    $front->registerPlugin( new Zend_Controller_Plugin_ErrorHandler() );
    $error = $front->getPlugin ('Zend_Controller_Plugin_ErrorHandler');
    $error->setErrorHandlerController('index');

    if (PHP_SAPI == 'cli')
    {
        $error->setErrorHandlerController ('error');
        $error->setErrorHandlerAction ('cli');
    }
}

You probably, also, want to munge more than one parameter from the command line, here's a basic example:

您可能还想从命令行中获取多个参数,下面是一个基本示例:

class Application_Router_Cli extends Zend_Controller_Router_Abstract
{
    public function route (Zend_Controller_Request_Abstract $dispatcher)
    {
        $getopt     = new Zend_Console_Getopt (array ());
        $arguments  = $getopt->getRemainingArgs();

        if ($arguments)
        {
            $command = array_shift( $arguments );
            $action  = array_shift( $arguments );
            if(!preg_match ('~\W~', $command) )
            {
                $dispatcher->setControllerName( $command );
                $dispatcher->setActionName( $action );
                $dispatcher->setParams( $arguments );
                return $dispatcher;
            }

            echo "Invalid command.\n", exit;

        }

        echo "No command given.\n", exit;
    }


    public function assemble ($userParams, $name = null, $reset = false, $encode = true)
    {
        echo "Not implemented\n", exit;
    }
}

Lastly, in your controller, the action that you invoke make use of the params that were orphaned by the removal of the controller and action by the CLI router:

最后,在您的控制器中,您调用的操作利用了由于删除控制器而孤立的params,以及CLI路由器的操作:

public function echoAction()
{
    // disable rendering as required
    $database_name     = $this->getRequest()->getParam(0);        
    $udata             = array();

    if( ($udata = $this->getRequest()->getParam( 1 )) )
        $udata         = explode( ",", $udata );

    echo $database_name;
    var_dump( $udata );
}

You could then invoke your CLI command with:

然后可以使用以下命令调用CLI命令:

php index.php Controller Action ....

For example, as above:

例如,上图:

php index.php Controller echo database123 this,becomes,an,array

You'll want to implement a more robust filtering/escaping, but, it's a quick building block. Hope this helps!

您将希望实现更健壮的筛选/转义,但是,这是一个快速构建块。希望这可以帮助!

#5


0  

One option is that you could fudge it by doing a wget on the URL that you use to invoke the desirable action

一种选择是,您可以通过对用于调用所需动作的URL执行wget来蒙混过关

#6


0  

You cant use -O option of wget to save the output. But wget is clearly NOT the solution. Prefer using CLI instead.

不能使用-O选项来保存输出。但wget显然不是解决方案。喜欢使用CLI。

#7


0  

akond idea works great, except the error exception isnt rendered by the error controller.

除了错误控制器没有呈现错误异常之外,这个想法非常有用。

public function cliAction() {
  $this->_helper->layout->disableLayout();
  $this->_helper->viewRenderer->setNoRender(true);

  foreach ($this->_getParam('error_handler') as $error) {
    if ($error instanceof Exception) {
      print "cli-error: " . $error->getMessage() . "\n";
    }
  }
}

and In Application_Router_Cli, comment off the echo and die statement

在Application_Router_Cli中,注释掉echo和die语句

public function assemble($userParams, $name = null, $reset = false, $encode = true) {
//echo "Not implemented\n";
}

#8


-1  

You can just use PHP as you would normally from the command line. If you call a script from PHP and either set the action in your script you can then run whatever you want.

您可以像通常在命令行中那样使用PHP。如果您从PHP调用一个脚本并在脚本中设置动作,那么您可以运行任何您想要的操作。

It would be quite simple really. Its not really the intended usage, however this is how it could work if you wanted to.

这真的很简单。它并不是真正想要的用法,但是如果您愿意,这就是它的工作方式。

For example

例如

 php script.php 

Read here: http://php.net/manual/en/features.commandline.php

在这里阅读:http://php.net/manual/en/features.commandline.php

#9


-1  

You can use wget command if your OS is Linux. For example:

如果您的操作系统是Linux,您可以使用wget命令。例如:

wget http://example.com/controller/action

See http://linux.about.com/od/commands/l/blcmdl1_wget.htm

参见http://linux.about.com/od/commands/l/blcmdl1_wget.htm

UPDATE:

更新:

You could write a simple bash script like this:

您可以编写这样一个简单的bash脚本:

if wget http://example.com/controller/action
    echo "Hello World!" > /home/wasdownloaded.txt
else
    "crap, wget timed out, let's remove the file."
    rm /home/wasdownloaded.txt
fi

Then you can do in PHP:

你可以用PHP来做

if (true === file_exists('/home/wasdownloaded.txt') {
    // to check that the 
}

Hope this helps.

希望这个有帮助。

#10


-2  

I have used wget command

我使用了wget命令

wget http://example.com/module/controller/action -O /dev/null

wget http://example.com/module/controller/action - o / dev / null

-O /dev/null if you dont want to save the output

-O /dev/null如果你不想保存输出

#1


60  

It's actually much easier than you might think. The bootstrap/application components and your existing configs can be reused with CLI scripts, while avoiding the MVC stack and unnecessary weight that is invoked in a HTTP request. This is one advantage to not using wget.

实际上比你想象的要简单得多。引导/应用程序组件和现有的配置可以与CLI脚本一起重用,同时避免在HTTP请求中调用MVC堆栈和不必要的权重。这是不使用wget的一个优点。

Start your script as your would your public index.php:

启动您的脚本,就像您的公共索引。php:

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH',
              realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV',
              (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 'production'));

require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/config.php'
);

//only load resources we need for script, in this case db and mail
$application->getBootstrap()->bootstrap(array('db', 'mail'));

You can then proceed to use ZF resources just as you would in an MVC application:

然后,您可以继续使用ZF资源,就像在MVC应用程序中那样:

$db = $application->getBootstrap()->getResource('db');

$row = $db->fetchRow('SELECT * FROM something');

If you wish to add configurable arguments to your CLI script, take a look at Zend_Console_Getopt

如果希望向CLI脚本添加可配置参数,请查看Zend_Console_Getopt

If you find that you have common code that you also call in MVC applications, look at wrapping it up in an object and calling that object's methods from both the MVC and the command line applications. This is general good practice.

如果您发现您有相同的代码,您也可以调用MVC应用程序,那么您可以将其封装到一个对象中,并从MVC和命令行应用程序中调用该对象的方法。这是一般的好习惯。

#2


63  

UPDATE

更新

You can have all this code adapted for ZF 1.12 from https://github.com/akond/zf-cli if you like.

While the solution #1 is ok, sometimes you want something more elaborate. Especially if you are expecting to have more than just one CLI script. If you allow me, I would propose another solution.

虽然解决方案#1是可行的,但有时您需要更精细的东西。特别是如果您希望拥有不止一个CLI脚本。如果你允许我,我将提出另一个解决办法。

First of all, have in your Bootstrap.php

首先,在Bootstrap.php中

protected function _initRouter ()
{
    if (PHP_SAPI == 'cli')
    {
        $this->bootstrap ('frontcontroller');
        $front = $this->getResource('frontcontroller');
        $front->setRouter (new Application_Router_Cli ());
        $front->setRequest (new Zend_Controller_Request_Simple ());
    }
}

This method will deprive dispatching control from default router in favour of our own router Application_Router_Cli.

此方法将从默认路由器中取消分派控制,而代之以我们自己的路由器Application_Router_Cli。

Incidentally, if you have defined your own routes in _initRoutes for your web interface, you would probably want to neutralize them when in command-line mode.

顺便说一下,如果您在web接口的_initpath中定义了自己的路由,您可能希望在使用命令行模式时消除它们。

protected function _initRoutes ()
{
    $router = Zend_Controller_Front::getInstance ()->getRouter ();
    if ($router instanceof Zend_Controller_Router_Rewrite)
    {
        // put your web-interface routes here, so they do not interfere
    }
}

Class Application_Router_Cli (I assume you have autoload switched on for Application prefix) may look like:

类Application_Router_Cli(我假设您已经为应用程序前缀打开了autoload)可能看起来如下:

class Application_Router_Cli extends Zend_Controller_Router_Abstract
{
    public function route (Zend_Controller_Request_Abstract $dispatcher)
    {
        $getopt = new Zend_Console_Getopt (array ());
        $arguments = $getopt->getRemainingArgs ();
        if ($arguments)
        {
            $command = array_shift ($arguments);
            if (! preg_match ('~\W~', $command))
            {
                $dispatcher->setControllerName ($command);
                $dispatcher->setActionName ('cli');
                unset ($_SERVER ['argv'] [1]);

                return $dispatcher;
            }

            echo "Invalid command.\n", exit;

        }

        echo "No command given.\n", exit;
    }


    public function assemble ($userParams, $name = null, $reset = false, $encode = true)
    {
        echo "Not implemented\n", exit;
    }
}

Now you can simply run your application by executing

现在,您可以通过执行来运行应用程序

php index.php backup

In this case cliAction method in BackupController controller will be called.

在这种情况下,将调用BackupController控制器中的cliAction方法。

class BackupController extends Zend_Controller_Action
{
    function cliAction ()
    {
        print "I'm here.\n";
    }
}

You can even go ahead and modify Application_Router_Cli class so that not "cli" action is taken every time, but something that user have chosen through an additional parameter.

您甚至可以继续修改Application_Router_Cli类,以便每次都不执行“cli”操作,而是用户通过附加参数选择的内容。

And one last thing. Define custom error handler for command-line interface so you won't be seeing any html code on your screen

最后一件事情。为命令行界面定义自定义错误处理程序,这样您就不会在屏幕上看到任何html代码

In Bootstrap.php

在Bootstrap.php

protected function _initError ()
{
    $error = $frontcontroller->getPlugin ('Zend_Controller_Plugin_ErrorHandler');
    $error->setErrorHandlerController ('index');

    if (PHP_SAPI == 'cli')
    {
        $error->setErrorHandlerController ('error');
        $error->setErrorHandlerAction ('cli');
    }
}

In ErrorController.php

在ErrorController.php

function cliAction ()
{
    $this->_helper->viewRenderer->setNoRender (true);

    foreach ($this->_getParam ('error_handler') as $error)
    {
        if ($error instanceof Exception)
        {
            print $error->getMessage () . "\n";
        }
    }
}

#3


7  

Just saw this one get tagged in my CP. If you stumbled onto this post and are using ZF2, it's gotten MUCH easier. Just edit your module.config.php's routes like so:

看到这个在我的CP中被标记了。如果你在这个帖子上被绊倒,并且正在使用ZF2,它会变得容易得多。编辑你的module.config。php的路线如下所示:

/**
 * Router
 */

'router' => array(
    'routes' => array(

        // .. these are your normal web routes, look further down
    ),
),

/**
 * Console Routes
 */
'console' => array(
    'router' => array(
        'routes' => array(

            /* Sample Route */
            'do-cli' => array(
                'options' => array(
                    'route'    => 'do cli',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'do-cli',
                    ),
                ),
            ),
        ),    
    ),
),

Using the config above, you would define doCliAction in your IndexController.php under your Application module. Running it is cake, from the command line:

使用上面的配置,您将在IndexController中定义doCliAction。在应用程序模块下的php。运行它是cake,从命令行:

php index.php do cli

php指数。cli php做

Done! Way smoother.

完成了!平滑方法。

#4


6  

akond's solution above is on the best track, but there are some subtleties that may may his script not work in your environment. Consider these tweaks to his answer:

akond的解决方案是在最好的轨道上,但是有一些微妙之处可能让他的脚本无法在你的环境中工作。考虑一下这些对他的回答的微调:

Bootstrap.php

Bootstrap.php

protected function _initRouter()
{
    if( PHP_SAPI == 'cli' )
    {
        $this->bootstrap( 'FrontController' );
        $front = $this->getResource( 'FrontController' );
        $front->setParam('disableOutputBuffering', true);
        $front->setRouter( new Application_Router_Cli() );
        $front->setRequest( new Zend_Controller_Request_Simple() );
    }
}

Init error would probably barf as written above, the error handler is probably not yet instantiated unless you've changed the default config.

Init错误可能会像上面所写的那样,barf,错误处理程序可能还没有实例化,除非您更改了默认配置。

protected function _initError ()
{
    $this->bootstrap( 'FrontController' );
    $front = $this->getResource( 'FrontController' );
    $front->registerPlugin( new Zend_Controller_Plugin_ErrorHandler() );
    $error = $front->getPlugin ('Zend_Controller_Plugin_ErrorHandler');
    $error->setErrorHandlerController('index');

    if (PHP_SAPI == 'cli')
    {
        $error->setErrorHandlerController ('error');
        $error->setErrorHandlerAction ('cli');
    }
}

You probably, also, want to munge more than one parameter from the command line, here's a basic example:

您可能还想从命令行中获取多个参数,下面是一个基本示例:

class Application_Router_Cli extends Zend_Controller_Router_Abstract
{
    public function route (Zend_Controller_Request_Abstract $dispatcher)
    {
        $getopt     = new Zend_Console_Getopt (array ());
        $arguments  = $getopt->getRemainingArgs();

        if ($arguments)
        {
            $command = array_shift( $arguments );
            $action  = array_shift( $arguments );
            if(!preg_match ('~\W~', $command) )
            {
                $dispatcher->setControllerName( $command );
                $dispatcher->setActionName( $action );
                $dispatcher->setParams( $arguments );
                return $dispatcher;
            }

            echo "Invalid command.\n", exit;

        }

        echo "No command given.\n", exit;
    }


    public function assemble ($userParams, $name = null, $reset = false, $encode = true)
    {
        echo "Not implemented\n", exit;
    }
}

Lastly, in your controller, the action that you invoke make use of the params that were orphaned by the removal of the controller and action by the CLI router:

最后,在您的控制器中,您调用的操作利用了由于删除控制器而孤立的params,以及CLI路由器的操作:

public function echoAction()
{
    // disable rendering as required
    $database_name     = $this->getRequest()->getParam(0);        
    $udata             = array();

    if( ($udata = $this->getRequest()->getParam( 1 )) )
        $udata         = explode( ",", $udata );

    echo $database_name;
    var_dump( $udata );
}

You could then invoke your CLI command with:

然后可以使用以下命令调用CLI命令:

php index.php Controller Action ....

For example, as above:

例如,上图:

php index.php Controller echo database123 this,becomes,an,array

You'll want to implement a more robust filtering/escaping, but, it's a quick building block. Hope this helps!

您将希望实现更健壮的筛选/转义,但是,这是一个快速构建块。希望这可以帮助!

#5


0  

One option is that you could fudge it by doing a wget on the URL that you use to invoke the desirable action

一种选择是,您可以通过对用于调用所需动作的URL执行wget来蒙混过关

#6


0  

You cant use -O option of wget to save the output. But wget is clearly NOT the solution. Prefer using CLI instead.

不能使用-O选项来保存输出。但wget显然不是解决方案。喜欢使用CLI。

#7


0  

akond idea works great, except the error exception isnt rendered by the error controller.

除了错误控制器没有呈现错误异常之外,这个想法非常有用。

public function cliAction() {
  $this->_helper->layout->disableLayout();
  $this->_helper->viewRenderer->setNoRender(true);

  foreach ($this->_getParam('error_handler') as $error) {
    if ($error instanceof Exception) {
      print "cli-error: " . $error->getMessage() . "\n";
    }
  }
}

and In Application_Router_Cli, comment off the echo and die statement

在Application_Router_Cli中,注释掉echo和die语句

public function assemble($userParams, $name = null, $reset = false, $encode = true) {
//echo "Not implemented\n";
}

#8


-1  

You can just use PHP as you would normally from the command line. If you call a script from PHP and either set the action in your script you can then run whatever you want.

您可以像通常在命令行中那样使用PHP。如果您从PHP调用一个脚本并在脚本中设置动作,那么您可以运行任何您想要的操作。

It would be quite simple really. Its not really the intended usage, however this is how it could work if you wanted to.

这真的很简单。它并不是真正想要的用法,但是如果您愿意,这就是它的工作方式。

For example

例如

 php script.php 

Read here: http://php.net/manual/en/features.commandline.php

在这里阅读:http://php.net/manual/en/features.commandline.php

#9


-1  

You can use wget command if your OS is Linux. For example:

如果您的操作系统是Linux,您可以使用wget命令。例如:

wget http://example.com/controller/action

See http://linux.about.com/od/commands/l/blcmdl1_wget.htm

参见http://linux.about.com/od/commands/l/blcmdl1_wget.htm

UPDATE:

更新:

You could write a simple bash script like this:

您可以编写这样一个简单的bash脚本:

if wget http://example.com/controller/action
    echo "Hello World!" > /home/wasdownloaded.txt
else
    "crap, wget timed out, let's remove the file."
    rm /home/wasdownloaded.txt
fi

Then you can do in PHP:

你可以用PHP来做

if (true === file_exists('/home/wasdownloaded.txt') {
    // to check that the 
}

Hope this helps.

希望这个有帮助。

#10


-2  

I have used wget command

我使用了wget命令

wget http://example.com/module/controller/action -O /dev/null

wget http://example.com/module/controller/action - o / dev / null

-O /dev/null if you dont want to save the output

-O /dev/null如果你不想保存输出