30.07.2012 Views

Reference Guide

Reference Guide

Reference Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Zend Server <strong>Reference</strong> Manual<br />

Ranges for each field:<br />

Field Range Comments<br />

Minute 0 - 59<br />

Hour 0 - 23 In 24 hour format, where 0 is midnight<br />

Day of Month 1 - 31 29,30 and 31 will only work for months of that length<br />

Month 1 - 12<br />

Day of Week 0 - 7 Sunday is either 0 or 7<br />

One-Time Deferred Tasks (jobs)<br />

This procedure describes how to create a one-time deferred task. In some use cases, it makes sense to<br />

defer a certain task to a later time. For example, many applications have clear peak hours (e.g. between<br />

8am and 11pm, or like in many Intranet applications, during office work hours).<br />

If these applications need to perform some off-line processing, it might make sense to defer some of the<br />

heavy processing tasks to off hours (in our examples to late night or early morning hours), in order to<br />

maximize the efficiency of hardware utilization.<br />

Note<br />

136<br />

To create a time deferred task:<br />

1. Follow the instructions in Queued Jobs to create an createHttpJob job using the API.<br />

2. Pass a date/time string as the schedule_time option, as part of the options array passed<br />

as the 3rd parameter to createHttpJob().<br />

The format used in date() to pass the execution time – this is an SQL-like ‘YYYY-MM-DD<br />

hh:mm:ss’format (e.g. “2009-06-25 23:45:00” for June 25th 2009 at 45 minutes past 11pm).<br />

Zend Job Queue is not designed to execute jobs exactly on the specified time. For example, if the queue<br />

is limited to execute 10 jobs concurrently (more on that later on), and 1,000 jobs are scheduled for the<br />

exact same time – jobs will have to wait until other jobs finish. You should consider the schedule_time<br />

option as a request not to run a job before this time.<br />

Example:<br />

The following example shows a time-deferred task that has been scheduled to run a process at<br />

2:00am.<br />

$options = array(<br />

'schedule_time' => date('Y-m-d h:i:s', strtotime('tomorrow 2am'))<br />

);<br />

$jq->createHttpJob('http://localhost/jobs/formproc.php', $_POST,<br />

$options);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!