@H_
404_0@
我有一个zendframework项目,我需要定期运行一个脚本来
上传文件夹的
内容,另一个需要下载.脚本本身已经准备就绪,但我正在努力弄清楚在哪里或如何设置要运行的脚本.到目前为止,我尝试过ly and和卷曲.我首先得到一个关于指定控制器
错误的
错误,我修复了但现在我只是在运行脚本时得到一个空白的屏幕,但
文件没有
上传.
对于zendframework项目,如何设置由cron运行的脚本?
编辑:
我的项目结构如下所示:
mydomain.com
application
library
logs
public
index.PHP
scripts
cronjob.PHP
tests
cronjob.PHP是我需要运行的脚本.前几行是:
<?PHP
define("_CRONJOB_",true);
require('/var/www/remotedomain.info/public/index.PHP');
我还修改了我的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();
}
但是现在当我现在尝试运行脚本时,我收到消息:
Message: Invalid controller specified (scripts).
这是否意味着我需要为此目的创建一个控制器?但脚本文件夹位于应用程序文件夹之外.我该如何解决?
谢谢大家的回答.然而,对我有用的
解决方案来自这个网站
Howto: Zend Framework Cron.原始
链接已经死亡,但
its copy可以在Internet Archive上找到.
我在这里发布了一些代码.但请这不是我的解决方案.所有学分都归原作者所有.
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
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
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,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();
}