如何设置作为zend框架项目一部分的脚本的cron作业

Nap*_*eon 10 cron zend-framework

我有一个zendframework项目,我需要定期运行一个脚本来上传文件夹的内容,另一个下载.脚本本身已准备好但我正在努力弄清楚在哪里或如何设置要运行的脚本.到目前为止,我尝试过ly and和卷曲.我首先得到一个关于指定控制器错误的错误,我修复了但现在我只是在运行脚本时得到一个空白的屏幕,但文件没有上传.

对于zendframework项目,如何设置由cron运行的脚本?

编辑: 我的项目结构如下:

mydomain.com

    application
    library
    logs
    public
        index.php
    scripts
        cronjob.php
    tests
Run Code Online (Sandbox Code Playgroud)

cronjob.php是我需要运行的脚本.前几行是:

<?php
define("_CRONJOB_",true);
require('/var/www/remotedomain.info/public/index.php');
Run Code Online (Sandbox Code Playgroud)

我还修改了我的index.php文件,如下所示:

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();

/** Cronjobs don't need all the extra's **/
if(!defined('_CRONJOB_') || _CRONJOB_ == false)
{
    $application->bootstrap()->run();
}
Run Code Online (Sandbox Code Playgroud)

但是现在当我现在尝试运行脚本时,我收到消息:

Message: Invalid controller specified (scripts).
Run Code Online (Sandbox Code Playgroud)

这是否意味着我需要为此目的创建一个控制器?但脚本文件夹位于应用程序文件夹之外.我该如何解决?

Nap*_*eon 11

谢谢大家的回答.然而,对我有用的解决方案来自这个网站Howto:Zend Framework Cron.原始链接已死,但其副本可以在Internet Archive上找到.

我在这里发布了一些代码.但请这不是我的解决方案.所有学分都归原作者所有.

使用cronjobs的诀窍是你不想加载ZF的整个View部分,我们不需要任何类型的HTML输出!为了实现这一点,我在cronjob.php中定义了一个新的常量,我将在index.php中检查它.

cronjob.php

define("_CRONJOB_",true);
require('/var/www/vhosts/domain.com/public/index.php');
// rest of your code goes here, you can use all Zend components now!
Run Code Online (Sandbox Code Playgroud)

的index.php

date_default_timezone_set('Europe/Amsterdam');

// 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'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();

/** Cronjobs don't need all the extra's **/
if(!defined('_CRONJOB_') || _CRONJOB_ == false)
{
$application->bootstrap()->run();
}
Run Code Online (Sandbox Code Playgroud)