Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>ZF2 doesn't have a "cron job" service to automatically run scripts at a specific time.</strong> </p> <p>A Cron Job is a task performed at a certain time and is typically setup at the operating system level. In unix, it's accomplished via the crontab, in windows you can use the task scheduler. There is nothing in ZF2 which will run your scripts at exactly 12:00 and 12:10.</p> <p><strong>Option #1: Cron Job via Admin Panel</strong></p> <p>For most hosting environments, you can setup a "cron job" via your website hosting admin panel (such as Plesk or cPanel). There you'll be able to schedule a job by entering in the time and the command to be run. When you create a cron job this way, keep in mind that you'll be entering a command to be run via the command line. Usually this is directly calling php to execute a specific script, but you could also use <a href="http://en.wikipedia.org/wiki/Wget" rel="nofollow noreferrer">wget</a> to fetch any URL from the internet. If you directly call php, you'll need to setup a console route as per Zdenek's answer.</p> <pre><code>/usr/bin/php /path/to/zf2/public/index.php myIndexConsoleRoute </code></pre> <p>or</p> <pre><code>wget http://yoursite.com/fetch-from-source/index </code></pre> <p><strong>Option #2: Setup Crontab via command line</strong></p> <p>Alternatively, if you have command line access to your server and the proper user permissions, you can setup a crontab via the command line per Zdenek's answer. There is also relevant info <a href="https://stackoverflow.com/questions/19752109/how-to-run-cron-job-with-zend-framework-2">here</a>. This is typically the preferred method, but in my opinion it's a bit more involved and can be a challenge to setup and debug, especially if you're not experienced with Unix.</p> <p><strong>Option #3: Cron Job service</strong> If you're looking for a simpler solution, you might consider one of the cron services out there which will load a specific URL at a given time.</p> <p>For example, I've used this service in the past: <a href="https://www.setcronjob.com" rel="nofollow noreferrer">https://www.setcronjob.com</a></p> <p>After you create your account, you simply enter a URL and select the time you'd like the URL to be called. You could easily accomplish your requirements to call the indexAction at 12:00 and icalAction at 12:10 by setting up two jobs, one to run at 12:00 and the other to run at 12:10. SetCronjob has a free plan which might fit your needs, but be aware that they require you to enter in a captcha every 30 days to renew your free account (which is fine, but becomes annoying after awhile).</p> <p><strong>URL vs Command Line</strong></p> <p>With "wget" in Option #1 and a Cron Service in Option #3, you'll need to make your indexAction and icalAction available via http. This could be a significant consideration. Even if you add some sort of validation (by checking for a code you send via query string or post), it's still possible that anyone on the internet could trigger these functions if they know the correct 'secret' URL. Having your ical and index methods accessed via http has the additional benefit of you being able to easily call them if you want to manually run these scripts to force an update.</p> <p>With the CLI approach mentioned by Zdenek, you create a console route in ZF2 and the only way to trigger that route is via the command line. This is typically preferred because your index and ical methods won't be exposed to http, but it's not always an option depending on your hosting setup, and it might not be a significant concern depending on what these functions do to your data and public website.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload