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