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.
For a zendframework project how do I setup script to be run by cron?
EDIT: My project structure looks like this:
mydomain.com
application
library
logs
public
index.php
scripts
cronjob.php
tests
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');
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?
First, make sure you have this at the top of your PHP script (followed by the opening PHP tag):
Second, make sure the permissions are right. For example, if you create the cron job under root, then I believe root will try to run the PHP script if I'm not mistaken. Likewise, if you create the cron job under a different user, they better have the correct permissions to the PHP script.
For example (note, depending on your server environment, the permissions will need to be adjusted accordingly. e.g. this is just a hypothetical example)
If you want to see the current cron jobs for the current user you're logged in as, do this:
Or, if your cron job is set up in one of the folders such as cron.hourly, cron.weekly, etc, then you can view which user "owns" those jobs by doing this:
Then at the bottom of the file you'll see them.
Now, to setup the cron job run this command to open the editor:
Then enter your values:
Now save and close the file. Obviously, you're going to change
1 2 3 4 5
to something real and meaningful. For more information about that see this page (google "cron").Disclaimer: I am not a cron master by any means. Please correct me on any of this if I'm wrong.
What I did was create a mini app called Scripts here is the structure:
I then use php /path/to/Scripts/Index.php --j=folderScript or /path/to/Scripts/Index.php --b=folderScript for a build script
I then overload the main zend_application bootstrap run method like so
Hope that gets you started, I looked at using a controller / module within ZF but seemed like too much overhead
Symfony uses a good approach with their app/console as well, could be worth looking into their setup
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.
cronjob.php
index.php