我如何设置cron作为zend框架项目一部分的脚本 [英] How do I setup a cron job a script that is part of a zend framework project

查看:142
本文介绍了我如何设置cron作为zend框架项目一部分的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个zendframework项目,我需要定期运行脚本上传文件夹的内容,另一个做下载。脚本本身已经准备好了,但我正在努力弄清楚在哪里或如何设置脚本运行。我试过lynx和curl到目前为止。我首先有一个错误指定的控制器是错误的,我固定的,但现在我只是得到一个空白屏幕,当我运行脚本,但文件没有上传。

I have a zendframework project for which i need to run a script periodically to upload the content of a folder and another do download. The script itself is ready but I am struggling to figure out where or how to set up the script to run. I have tried lynx and curl so far. I first had an error about specified controller being wrong and i fixed that but now I just get a blank screen when I run the script but file(s) are not uploaded.

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

For a zendframework project how do I setup script to be run by cron?

编辑:
我的项目结构看起来像这样:

My project structure looks like this:

mydomain.com

    application
    library
    logs
    public
        index.php
    scripts
        cronjob.php
    tests

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

cronjob.php is the script i need to run. The first few lines of which are:

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

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

I also modified my index.php file like below:

// 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();
}

但是现在当我尝试运行脚本时,

However now when i now try to run the script, I get the message:

Message: Invalid controller specified (scripts).

这是不是意味着我需要创建一个控制器的目的?但是脚本文件夹在应用程序文件夹之外。我如何解决这个问题?

Does it mean that I need to create a controller for the purpose? But the script folder is outside the application folder. How do i fix this?

推荐答案

感谢您的答案。然而,为我工作的解决方案来自这个网站 Howto:Zend Framework Cron < a>。原始连结已失效,但其副本可以在Internet Archive上找到。

Thanks all for your answers. However the solution that worked for me came from this site Howto: Zend Framework Cron. The original link is dead, but its copy can be found on Internet Archive.

我在这里发布了一段代码。但请不要这是我的解决方案。

I am posting a cut of the code here. But please this is not my solution. All credits goes to the original author.


cronjobs的窍门是你不想加载整个视图
part的ZF,我们不需要任何类型的HTML输出!为了让
工作,我在cronjob.php中定义了一个新的常量,我将在index.php中检查

The trick with cronjobs is that you do not want to load the whole View part of ZF, we don't need any kind of HTML output! To get this to work, I defined a new constant in the cronjob.php which I will check for in the index.php.



cronjob.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!



index.php



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();
}

这篇关于我如何设置cron作为zend框架项目一部分的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆