Job Queue API

The Job Queue API contains a set of functions that enables to run a Job directly from your application's scripts. Running Jobs with the API, is beneficial in situations where a certain query has to be run in parallel with other actions. Such a situation could be in an online store where a user's credit card details have to be authenticated. In such a case the authentication process can be a Job that is activated when the user enters the credit card details. The authentication process, may take some time therefore, this job can be run separately on a separate server or even on a dedicated secure server (for credit card details). These Jobs can even be scheduled to run the authentication query at a later time when there is less traffic.

Usage Example


An example of this kind of script is as follows:


$job = new ZendAPI_Job('/usr/local/scripts/scrip1.php');


$job->setUserVariables(array('name' => 'customer name', 'email' => ''));           



This script should be added to the application's script, at the point where you want to run a query. As we can see from this example, the new Job ($job) contains information indicating to the location of a script (scrip1.php). This script will contain the query that we want to run. Surrounding that script are different parameters that define the Job's variables, priority and other essential information. This information is also picked up by Platform so that it can be viewed in the Jobs Tab eliminating the need to open numerous small files in order to find information relevant to managing Jobs.

Important Note:

All scripts managed by the Job Queue have to be placed in a set location. To view the default location or define a different location go to Job Queue | Settings and in the General Settings section view or change the Scripts Folder.

This naturally is only a simplified example of a basic Job that will run a query (script) and send an e-mail. The sections on APIs and Directives contain a complete description of the Job Queue API.

Usage Example

Additional Example:

Change the recurrence data of an existing job and add to it a dependency (assuming that the job id is known)


$job_queue = new ZendAPI_Queue('');


$job = $job_queue->getJob(8);

$job->setRecurrenceData(3600, time()+3600*24);

$job->setJobDependency(16);        // This job will perform only after job 16 was successfully executed

$job_queue->updateJob($job);            // The job queue will update job #8 with the new properties of the given Job object


Get all the jobs from a queue with urgent priority that waiting for process and belong to application id 8, change their priorities to LOW


$job_queue = new ZendAPI_Queue('');


$jobs = $job_queue->getJobsInQueue(

                array('priority' => JOB_QUEUE_PRIORITY_URGENT,

                      'status' => JOB_QUEUE_STATUS_WAITING

// we could also request for jobs in application id using the following line:

//'application_id' => 8



foreach ($jobs as $job) {    /* @var $job Job */







Related Links

Related Links:
Job Queue Functions

Job Queue Directives

Appendix A – Troubleshooting Zend Platform