SlideShare a Scribd company logo
Task Scheduling and Asynchronous Processing Evolved.  Zend Server Job Queue By   Sam Hennessy  – Zend Professional Services Consultant
Offline Processing Why? Perceived performance Managing load Any work that isn’t needed for giving feedback to the user should be done offline.
Offline Processing Examples Sending e-mails Processing orders Indexing new content Cleaning the database or file system Either periodically or after some user action Pulling an RSS feed every hour Checking exchange rates every day Generating periodical reports
Blog Example Post comment Save in the DB Rebuild RSS feeds Send email notifications Display “Thank You” message
Blog Example Post comment Save in the DB Rebuild RSS feeds Send email notifications Display thank you message Queue Tasks Job Queue
Architectural Overview PHP + Job Queue Extension TCP or Unix Socket Job Queue Damon Persistent Storage (SQLite) HTTP Request Executing Server
Goals Of Zend Job Queues Ability to off-load PHP code execution Jobs should never be “lost” Ability to queue jobs from PHP API Ability to create recurring & deferred jobs Management GUI
The  ZendJobQueue  class The  ZendJobQueue  class contains almost all the PHP API for Job Queue To perform most tasks, you will need to connect to a Job Queue server by instantiating a  ZendJobQueue  object: // Connect to the default JQ server  $queue  = new  ZendJobQueue ();  // Connect to any other JQ server  $queue  = new  ZendJobQueue ( "tcp://1.2.3.4:5678" );
Creating Jobs All jobs are created using the  ZendJobQueue::createHttpJob()  method Passing a partial URL will create the job with  $_SERVER['HTTP_HOST']  in the host nam e $queue  = new  ZendJobQueue ();  $queue -> createHttpJob ( 'http://backend.local/jobs/somejob.php' ); $queue -> createHttpJob ( '/jobs/otherjob.php' );
Passing Parameters Simple parameters can be passed as part of the query string Complex parameters can also be passed Pass any serializable data as the 2 nd  parameter of  createHttpJob() Data will be JSON-encoded – so anything which can be represented as JSON can be used $queue -> createHttpJob ( '/jobs/otherjob.php?foo=bar&uid=1792' );
Passing Parameters (example) $params  = array(     'cart'  => array(       'items'  => array(        array( 'id'  =>  324 ,  'qty'  =>  1 ,  'price'  =>  19.95 ),        array( 'id'  =>  75 ,  'qty'  =>  2 ,  'price'  =>  14.95 ,            'size'   =>  'XL' )      ),       'total'      =>  49.85 ,       'coupon'     =>  null ,       'giftwrap'   =>  true      ),     'user'  =>  $user  );  $queue -> createHttpJob (    'http://backend/jobs/checkout.php' ,  $params );
Accessing Parameters Inside the Job code, use the  ZendJobQueue::getCurrentJobParams()  static method to get the job's parameters: You can also  json_decode()  the raw POST data $params  =  ZendJobQueue :: getCurrentJobParams (); $params  =  json_decode ( file_get_contents ( 'php://input' ));
Additional Job Options The 3 rd  parameter of  createHttpJob  is an associative array of parameters: name priority persistent predecessor http_headers schedule schedule_time
Creating Deferred Jobs You can set a job's (estimated) execution time  by passing the  schedule_time  option: The job will not run  before  the specified time // Process the form at 3:00 am  $runAt   =  date ( 'Y-m-d h:i:s' ,  strtotime ( '+1 day 3:00am' ));  $options   = array(     'schedule_time'  =>  $runAt  );  $queue -> createHttpJob ( 'http://backend/jobs/process.php' ,      $_POST ,  $options );
Creating Recurring Jobs You can create a recurring job from API using the  schedule  option This option takes a cron-like expression that specifies scheduling // Run on Sunday, Monday, and Tuesday at midnight     $jq -> createHttpJob ( 'http://localhost/jobs/feed/405' ,  null , array(          'schedule'  =>  '0 0 * * 0,1,2'     ));        // Run every other day of the month at 2:30pm     $jq -> createHttpJob ( 'http://localhost/jobs/feed/405' ,  null , array(          'schedule'  =>  '30 14 */2 * *'     ));
Reporting Logical Failures A logical failure happens when something has programatically failed e.g. you were unable to send an e-mail or connect to a SOAP web service Unlike an execution failure which is a technical failure (e.g. 500 error from server) Logical failures need to be reported by the programmer: ZendJobQueue :: setCurrentJobStatus ( ZendJobQueue :: OK );   if (!  doTheImportantStuff ()) {     ZendJobQueue :: setCurrentJobStatus ( ZendJobQueue :: ERROR );  }
Job HTTP Request POST /job.php HTTP/1.0 Host: localhost Content-Type: text/json Content-Length: 34 Connection: close Accept: */* USER_AGENT: Zend Server Job Queue/4.1 Cookie: SESS273df6b85bb9a37ced781f806219fc6a=7k6atppt8akccooobs26htsim7; ZDEDebuggerPresent=php,phtml,php3 {"var1":15,"nested":["a","b","c"]}
Job HTTP Response HTTP/1.1 200 OK Date: Thu, 10 Sep 2009 17:29:20 GMT Server: Apache/2.2.9 (Debian) PHP/5.2.10 X-Powered-By: PHP/5.2.10 ZendServer/4.0 Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/ X-Job-Queue-Status: 1 Something is wrong! Vary: Accept-Encoding Content-Length: 152 Connection: close Content-Type: text/html array(2) { ["var1"]=> int(15) ["nested"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } }
Live Demo
Questions?
Thank You! Please come find me if you have any more questions
Ad

Recommended

PDF
Scalable web application architecture
postrational
 
PPTX
Hooking with WordPress by Rahul Prajapati - COEP FOSSMeet March 2019
rtCamp
 
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 
PPTX
Working with WP_Query in WordPress
topher1kenobe
 
PPT
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Gosuke Miyashita
 
PDF
Search 500-video-clips
phanhung20
 
PPT
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
PDF
Symfony2 Components - The Event Dispatcher
Sarah El-Atm
 
PPTX
Django Girls Tutorial
Kishimi Ibrahim Ishaq
 
PDF
Rest api with Python
Santosh Ghimire
 
PPTX
Introduction tomongodb
Lee Theobald
 
PDF
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
PDF
Introduction to AngularJS For WordPress Developers
Caldera Labs
 
PDF
Django Introduction & Tutorial
之宇 趙
 
ODP
node.js - Fast event based web application development
openForce Information Technology GesmbH
 
ODP
CouchApp - Build scalable web applications and relax
openForce Information Technology GesmbH
 
PDF
Practical Celery
Cameron Maske
 
PDF
RSpec User Stories
rahoulb
 
PPT
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
PDF
You Don't Know Query - WordCamp Portland 2011
andrewnacin
 
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
PDF
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Caldera Labs
 
PDF
AJAX Transport Layer
Siarhei Barysiuk
 
KEY
LvivPy - Flask in details
Max Klymyshyn
 
PDF
Flask patterns
it-people
 
PDF
PWA 與 Service Worker
Anna Su
 
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
andrewnacin
 
PDF
Writing Software not Code with Cucumber
Ben Mabey
 
PPTX
Magento's Imagine eCommerce Conference: Do You Queue?
varien
 
PPTX
Slideshare - Magento Imagine - Do You Queue
10n Software, LLC
 

More Related Content

What's hot (20)

PPTX
Django Girls Tutorial
Kishimi Ibrahim Ishaq
 
PDF
Rest api with Python
Santosh Ghimire
 
PPTX
Introduction tomongodb
Lee Theobald
 
PDF
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
PDF
Introduction to AngularJS For WordPress Developers
Caldera Labs
 
PDF
Django Introduction & Tutorial
之宇 趙
 
ODP
node.js - Fast event based web application development
openForce Information Technology GesmbH
 
ODP
CouchApp - Build scalable web applications and relax
openForce Information Technology GesmbH
 
PDF
Practical Celery
Cameron Maske
 
PDF
RSpec User Stories
rahoulb
 
PPT
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
PDF
You Don't Know Query - WordCamp Portland 2011
andrewnacin
 
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
PDF
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Caldera Labs
 
PDF
AJAX Transport Layer
Siarhei Barysiuk
 
KEY
LvivPy - Flask in details
Max Klymyshyn
 
PDF
Flask patterns
it-people
 
PDF
PWA 與 Service Worker
Anna Su
 
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
andrewnacin
 
PDF
Writing Software not Code with Cucumber
Ben Mabey
 
Django Girls Tutorial
Kishimi Ibrahim Ishaq
 
Rest api with Python
Santosh Ghimire
 
Introduction tomongodb
Lee Theobald
 
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Introduction to AngularJS For WordPress Developers
Caldera Labs
 
Django Introduction & Tutorial
之宇 趙
 
node.js - Fast event based web application development
openForce Information Technology GesmbH
 
CouchApp - Build scalable web applications and relax
openForce Information Technology GesmbH
 
Practical Celery
Cameron Maske
 
RSpec User Stories
rahoulb
 
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
You Don't Know Query - WordCamp Portland 2011
andrewnacin
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Caldera Labs
 
AJAX Transport Layer
Siarhei Barysiuk
 
LvivPy - Flask in details
Max Klymyshyn
 
Flask patterns
it-people
 
PWA 與 Service Worker
Anna Su
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
andrewnacin
 
Writing Software not Code with Cucumber
Ben Mabey
 

Similar to Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue (20)

PPTX
Magento's Imagine eCommerce Conference: Do You Queue?
varien
 
PPTX
Slideshare - Magento Imagine - Do You Queue
10n Software, LLC
 
PPTX
Do you queue (updated)
10n Software, LLC
 
PDF
Queue your work
Jurian Sluiman
 
PDF
Faster PHP apps using Queues and Workers
Richard Baker
 
PDF
Job Queue Presentation - OSSCamp 2014
OSSCube
 
PPTX
North east user group tour
10n Software, LLC
 
ODP
Introduction to Python Celery
Mahendra M
 
ODP
Drupal course - batch API
Dániel Kalmár
 
PDF
2015 ZendCon - Do you queue
Mike Willbanks
 
PPTX
Do you queue
10n Software, LLC
 
PPTX
Job Queues Overview
joeyrobert
 
PDF
Symfony bundle fo asynchronous job processing
Wojciech Ciołko
 
KEY
Work Queues
ciconf
 
PDF
Delayed operations with queues for website performance
OSInet
 
PPT
Job Queue - web is more than request and response
Abhinav Lal
 
PDF
Why Task Queues - ComoRichWeb
Bryan Helmig
 
PPTX
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking VN
 
KEY
Gearman and CodeIgniter
Erik Giberti
 
PDF
Distributed Queue System using Gearman
Eric Cho
 
Magento's Imagine eCommerce Conference: Do You Queue?
varien
 
Slideshare - Magento Imagine - Do You Queue
10n Software, LLC
 
Do you queue (updated)
10n Software, LLC
 
Queue your work
Jurian Sluiman
 
Faster PHP apps using Queues and Workers
Richard Baker
 
Job Queue Presentation - OSSCamp 2014
OSSCube
 
North east user group tour
10n Software, LLC
 
Introduction to Python Celery
Mahendra M
 
Drupal course - batch API
Dániel Kalmár
 
2015 ZendCon - Do you queue
Mike Willbanks
 
Do you queue
10n Software, LLC
 
Job Queues Overview
joeyrobert
 
Symfony bundle fo asynchronous job processing
Wojciech Ciołko
 
Work Queues
ciconf
 
Delayed operations with queues for website performance
OSInet
 
Job Queue - web is more than request and response
Abhinav Lal
 
Why Task Queues - ComoRichWeb
Bryan Helmig
 
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking VN
 
Gearman and CodeIgniter
Erik Giberti
 
Distributed Queue System using Gearman
Eric Cho
 
Ad

Recently uploaded (20)

PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PDF
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PDF
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
PDF
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
PDF
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
PDF
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Ad

Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue

  • 1. Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue By Sam Hennessy – Zend Professional Services Consultant
  • 2. Offline Processing Why? Perceived performance Managing load Any work that isn’t needed for giving feedback to the user should be done offline.
  • 3. Offline Processing Examples Sending e-mails Processing orders Indexing new content Cleaning the database or file system Either periodically or after some user action Pulling an RSS feed every hour Checking exchange rates every day Generating periodical reports
  • 4. Blog Example Post comment Save in the DB Rebuild RSS feeds Send email notifications Display “Thank You” message
  • 5. Blog Example Post comment Save in the DB Rebuild RSS feeds Send email notifications Display thank you message Queue Tasks Job Queue
  • 6. Architectural Overview PHP + Job Queue Extension TCP or Unix Socket Job Queue Damon Persistent Storage (SQLite) HTTP Request Executing Server
  • 7. Goals Of Zend Job Queues Ability to off-load PHP code execution Jobs should never be “lost” Ability to queue jobs from PHP API Ability to create recurring & deferred jobs Management GUI
  • 8. The ZendJobQueue class The ZendJobQueue class contains almost all the PHP API for Job Queue To perform most tasks, you will need to connect to a Job Queue server by instantiating a ZendJobQueue object: // Connect to the default JQ server $queue  = new  ZendJobQueue (); // Connect to any other JQ server $queue  = new  ZendJobQueue ( "tcp://1.2.3.4:5678" );
  • 9. Creating Jobs All jobs are created using the ZendJobQueue::createHttpJob() method Passing a partial URL will create the job with $_SERVER['HTTP_HOST'] in the host nam e $queue  = new  ZendJobQueue (); $queue -> createHttpJob ( 'http://backend.local/jobs/somejob.php' ); $queue -> createHttpJob ( '/jobs/otherjob.php' );
  • 10. Passing Parameters Simple parameters can be passed as part of the query string Complex parameters can also be passed Pass any serializable data as the 2 nd parameter of createHttpJob() Data will be JSON-encoded – so anything which can be represented as JSON can be used $queue -> createHttpJob ( '/jobs/otherjob.php?foo=bar&uid=1792' );
  • 11. Passing Parameters (example) $params = array(    'cart'  => array(      'items'  => array(       array( 'id'  =>  324 ,  'qty'  =>  1 ,  'price'  =>  19.95 ),       array( 'id'  =>  75 ,  'qty'  =>  2 ,  'price'  =>  14.95 ,           'size'  =>  'XL' )     ),      'total'     =>  49.85 ,      'coupon'    =>  null ,      'giftwrap'  =>  true     ),    'user'  =>  $user ); $queue -> createHttpJob (    'http://backend/jobs/checkout.php' ,  $params );
  • 12. Accessing Parameters Inside the Job code, use the ZendJobQueue::getCurrentJobParams() static method to get the job's parameters: You can also json_decode() the raw POST data $params  =  ZendJobQueue :: getCurrentJobParams (); $params  =  json_decode ( file_get_contents ( 'php://input' ));
  • 13. Additional Job Options The 3 rd parameter of createHttpJob is an associative array of parameters: name priority persistent predecessor http_headers schedule schedule_time
  • 14. Creating Deferred Jobs You can set a job's (estimated) execution time by passing the schedule_time option: The job will not run before the specified time // Process the form at 3:00 am $runAt  =  date ( 'Y-m-d h:i:s' ,  strtotime ( '+1 day 3:00am' )); $options  = array(    'schedule_time'  =>  $runAt ); $queue -> createHttpJob ( 'http://backend/jobs/process.php' ,     $_POST ,  $options );
  • 15. Creating Recurring Jobs You can create a recurring job from API using the schedule option This option takes a cron-like expression that specifies scheduling // Run on Sunday, Monday, and Tuesday at midnight    $jq -> createHttpJob ( 'http://localhost/jobs/feed/405' ,  null , array(         'schedule'  =>  '0 0 * * 0,1,2'    ));      // Run every other day of the month at 2:30pm    $jq -> createHttpJob ( 'http://localhost/jobs/feed/405' ,  null , array(         'schedule'  =>  '30 14 */2 * *'    ));
  • 16. Reporting Logical Failures A logical failure happens when something has programatically failed e.g. you were unable to send an e-mail or connect to a SOAP web service Unlike an execution failure which is a technical failure (e.g. 500 error from server) Logical failures need to be reported by the programmer: ZendJobQueue :: setCurrentJobStatus ( ZendJobQueue :: OK );  if (!  doTheImportantStuff ()) {    ZendJobQueue :: setCurrentJobStatus ( ZendJobQueue :: ERROR ); }
  • 17. Job HTTP Request POST /job.php HTTP/1.0 Host: localhost Content-Type: text/json Content-Length: 34 Connection: close Accept: */* USER_AGENT: Zend Server Job Queue/4.1 Cookie: SESS273df6b85bb9a37ced781f806219fc6a=7k6atppt8akccooobs26htsim7; ZDEDebuggerPresent=php,phtml,php3 {"var1":15,"nested":["a","b","c"]}
  • 18. Job HTTP Response HTTP/1.1 200 OK Date: Thu, 10 Sep 2009 17:29:20 GMT Server: Apache/2.2.9 (Debian) PHP/5.2.10 X-Powered-By: PHP/5.2.10 ZendServer/4.0 Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/ X-Job-Queue-Status: 1 Something is wrong! Vary: Accept-Encoding Content-Length: 152 Connection: close Content-Type: text/html array(2) { ["var1"]=> int(15) ["nested"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } }
  • 21. Thank You! Please come find me if you have any more questions