PHP Performance on IBM i - Seiden Group slides/PHP on IBM i... · PHP Performance on IBM i ... •...
Transcript of PHP Performance on IBM i - Seiden Group slides/PHP on IBM i... · PHP Performance on IBM i ... •...
PHP Performance on IBM i
Part 2 Accelerate your application
www.SeidenGroup.com
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Speaker: Alan Seiden
• Principal at Seiden Group • Mentor CIOs and development teams
• Deliver modern technical solutions
• Host and sponsor of CIO Summit
• Club Seiden: The next generation • Open source advocate, contributor
!2
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Seiden Group
!3
• Team of experts who: • Mentor IBM i teams, IT Directors, CIOs
• Consult on projects and process
• Develop applications
• Troubleshootwww.seidengroup.com
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Club Seiden
!4
Forum for younger developers with a passion for open source, IBM i and collaboration
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Second of three sessions on peformance
Session 1: How fast? Find the bottlenecks! (measure, measure, measure)
Session 2: Accelerate your application * (speed up PHP and the server back end)
Session 3: Ensuring a fast user experience (speed up the front end)
* You are here
!5
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Session agenda
• DB2 and PHP performance tips
• Toolkit
• Zend Server configuration for speed
• Reducing IFS accesses
• Go asynchronous
!6
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP 7
!7
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP 7 is faster than previous versions
!8
• PHP 7.x comes with Zend Server 9.x• Speed boost• Spurred by competition with Facebook’s “Hack”
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Let’s try a simple speed test<?php $profile['start'] = microtime( true );
for ($i=0 ; $i<1000000 ; $i++) { serialize($i); } $profile['end'] = microtime( true ); $profile['duration'] = $profile['end'] - $profile['start']; echo "Took " . $profile['duration']. " seconds ";
Try it from CALL QP2TERM or SSH terminal: cd /usr/local/zendsvr6/bin php -n /www/zendphp7/htdocs/test/speedtest.php cd /usr/local/zendphp7/bin php -n /www/zendphp7/htdocs/test/speedtest.php
!9
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP and Apache jobs
!10
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Number of PHP jobs
• FastCGI PHP “children” § /www/zendphp7/conf/fastcgi.conf § Default: SetEnv=“PHP_FCGI_CHILDREN=10" § Increase from 10 to # of expected concurrent PHP requests § Each “child” needs temp storage, CPU, memory; find a balance
§
!11
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Number of Apache HTTP threads
• Apache’s ThreadsPerChild • /www/zendphp7/conf/httpd.conf • Default: ThreadsPerChild 40 • Increase to number of expected HTTP connections
• PHP requests • CSS • Javascript • AJAX requests
!12
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Active and idle thread dashboard
• “Real-time server statistics” on HTTP Admin page
!13
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
DB2 and SQL
!14
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Specs
• OS matters: Newer OS releases speed up complex DB2 queries with a smarter query optimizer
• IBM i is built to scale as large as its resources ‣ Example: IBM i’s query optimizer will choose the best
plan it can, given the amount of memory available to it. More memory, a more intelligent plan.
!15
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
DB2 query optimization
• IBM i has great tools • You can find many articles written by DB2 experts
• I’ll share a couple of favorites ‣ Index Advisor ‣ SQL Plan Cache
• See IBM’s book • IBM i Database Performance and Query Optimization • http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/rzajq/
rzajq.pdf
!16
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Index Advisor
• Now in web-based Navigator and Access Client Solutions • Recommends indexes across all queries
!17
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
SQL Plan Cache
• Lets you see what queries are REALLY running, who’s running them, and how long they take
!18
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Persistent db connections
!19
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Persistent connections
•Create a pool of database jobs •Known as a “connection pool” •You will connect quickly because a job is waiting for you •DB2 will...
• Choose a job each time you run a query • Create new jobs to handle high workload
•The word “persistent” may be misleading •No guarantee that a PHP script connects to same job each
time •Cannot rely on maintaining state (QTEMP, library lists)
between requests !20
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
db2_pconnect() to connect persistently
•resource db2_pconnect ( string $database , string $username , string $password [, array $options ] )
• Persistent is much faster than non-persistent § db2_pconnect can reuse connections, reducing the time needed
to connect (after the first time) to almost zero
• How db2_pconnect() reuses connections § Connections defined by database, username, and password § Tries to reuse an existing connection matching these 3 params § db2_close() on a persistent connection does nothing § db2_pclose() forces the conn to close
!21
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Rules for using persistence
• Because connections are shared when defined with an identical database, user, and password, please: § Avoid unpredictable results by also specifying the same $options
for these connections § Promote sharing of jobs by minimizing the number of user
profiles that you connect with • Each user profile creates a new set of database jobs • Each set of jobs consumes system resources when they start • Though jobs don’t do much harm once they are started
!22
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Persistence = connection pool
• On IBM i, job initialization is relatively slow § Gives us good things—auditing, logging, security § Solution: a pool of pre-initialized jobs
• Pre-started DB2 jobs save time § Generally run in subsystem QSYSWRK, job name QSQSRVR § These prestart jobs can be configured with CHGPJE command
• In PHP, persistent connections reuse initialized jobs § db2_pconnect() § Dramatic speed boost
!23
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
db2_pconnect() example with library list
$database = 'MYDB';
$user = 'MYUSER'; $password = 'MYPASS';
// set library list (works the same for connect or pconnect)
$options = array('i5_naming' => DB2_I5_NAMING_ON, 'i5_libl' => 'MYLIB1 MYLIB2'
); $conn = db2_pconnect($database, $user, $password, $options);
if ($conn) {
echo "Connection succeeded."; } else { echo "Connection failed.";
} // MYTABLE will be found, if in library MYLIB1 or MYLIB2
$stmt=db2_exec($conn,"SELECT * FROM MYTABLE");
!24
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Rules for using persistence
• Because connections are shared when defined with an identical database, user, and password, please: § Avoid unpredictable results by also specifying the same $options
for these connections § Promote sharing of jobs by minimizing the number of user
profiles that you connect with • Each user profile creates a new set of database jobs • Each set of jobs consumes system resources
• More information: § “DB2 and PHP Best Practices on IBM i” at http://
seidengroup.com/presentations
!25
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
More about db2_connect, db2_pconnect
•Manual pages § http://www.php.net/manual/en/function.db2-
connect.php § http://www.php.net/manual/en/function.db2-
pconnect.php § http://www.php.net/manual/en/features.persistent-
connections.php
!26
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
DB2 server prestart job configuration
• Prestart jobs named QSQSRVR run in QSYSWRK • Or, if remote DRDA, QRWTSRVR in QUSRWRK • Configurable pool of jobs CHGPJE SBSD(QSYS/QSYSWRK) PGM(QSYS/QSQSRVR)
STRJOBS(*YES) INLJOBS(xx) THRESHOLD(xx) ADLJOBS(xx) MAXUSE(xx or *NOMAX)
• Defaults are somewhat low ‣ Initial jobs = 5, threshold = 2, adljobs = 2. Maxuse = 200
(*NOMAX may be better)
• More information about QSQSRVR prestart jobs ‣ http://www.mcpressonline.com/tips-techniques/database/techtip-
grab-control-of-the-db2-qsqsrvr-jobs.html
!27
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
If you increase the prestart jobs...
• Consider increasing FastCGI and Apache settings mentioned in Session 1
‣ FastCGI PHP children ‣ Look in /www/zendphp7/conf/fastcgi.conf ‣ Default: SetEnv=“PHP_FCGI_CHILDREN=10" ‣ Increase from 10 to # of expected concurrent PHP requests ‣ Each “child” needs temp storage, CPU, memory; find a balance
‣ Next, Apache’s ThreadsPerChild ‣ /www/zendphp7/conf/httpd.conf ‣ Default: ThreadsPerChild 40 ‣ Increase to number of expected HTTP connections
!28
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP Toolkit
!29
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Call RPG/COBOL: adapt 5250 logic to the web
!30
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Toolkit Architecture
!31
RPG, COBOL, System Resources
XMLSERVICE
Your PHP code
Toolkit
Toolkit Methods
Sends XML
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP IBM i toolkit is open source
• Ships with Zend Server 5.6+ ‣ Many improvements since first release
• Where to start ‣ https://www.seidengroup.com/toolkit/
• Zend Forum ‣ http://forums.zend.com/viewtopic.php?f=113&t=41648 ‣ “PHP on IBM i”->”Zend Server for IBM i”->”New Toolkit” ‣ Many tips there
!32
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Performance “don’t”s
• Don’t use disconnect() unless it’s the end of the day, logout, etc. ‣ Reconnection in stateful mode is slow ‣ Official samples set a bad example here
• Don’t allow inquiry messages to arise, hanging your job ‣ MONMSG in CL is one way to address
• Don’t run commands or programs with warning CPF ‣ Example: ADDLIBLE can return “already exists” error. Prefer CHGLIBL or
other technique ‣ Toolkit will fetch joblog for error reporting, which can be slow ‣ Not XMLSERVICE’s fault…in future we may allow “fast” (no joblog) mode
sometimes for non-critical errors
!33
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Performance “do”s
• Don’t use disconnect() unless it’s the end of the day, logout, etc. ‣ Reconnection in stateful mode is slow ‣ Official samples set a bad example here
• Don’t allow inquiry messages to arise, hanging your job ‣ MONMSG in CL is one way to address
• Don’t run commands or programs with warning CPF ‣ Example: ADDLIBLE can return “already exists” error. Prefer CHGLIBL or
other technique ‣ Toolkit will fetch joblog for error reporting, which can be slow ‣ Not XMLSERVICE’s fault…in future we may allow “fast” (no joblog) mode
sometimes for non-critical errors
!34
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Share existing DB2 conn with toolkit
Either db2_pconnect or regular db2_connect can be used. Share a connection instead of creating a new one in the toolkit.
require_once('ToolkitService.php');
// connect to db using chosen i5 naming mode
$namingMode = DB2_I5_NAMING_ON; // ON or OFF // connect to db
$db = db2_connect('DBNAME', 'user', 'pass', array('i5_naming' => $namingMode));
// Connect to toolkit, passing db resource and i5 naming mode instead of dbname/user/password.
$conn = ToolkitService::getInstance($db, $namingMode);
!35
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Avoid RTV* commands if need speed
• RTVJOBA, RTVUSRPRF, etc. ‣ Handy for diagnostics, and they work fine ‣ Inside the toolkit they use REXX, which makes them slow ‣ Avoid in production environments that need to scale ‣ Alternative: compile RTV* command into a CL, then call the CL from
toolkit
// RTVJOBA works but is relatively slow require_once('ToolkitService.php');
$cmdString = 'RTVJOBA JOB(?) USER(?) NBR(?) CURUSER(?) SYSLIBL(?) CURLIB(?) USRLIBL(?) LANGID(?) CNTRYID(?) CCSID(?N) DFTCCSID(?N)'; // Send the command; get output array of key/value pairs. Example: CURUSER=>FRED, ...
$outputArray = $this->ClCommandWithOutput($cmdString);
!36
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Do not use disconnect()
• The disconnect() method ends the toolkit job • When you connect again it will be slow to restart • Better to leave the job running. It will not use much resources
when idle • If you really want the toolkit job to end, use “idle timeout,”
where the job ends after a period of inactivity
require_once('ToolkitService.php'); $conn = ..... connect....
$conn->setOptions(‘internalKey’=>’/tmp/alan123’)); // end job after an hour of inactivity
$conn->setOptions(array(‘idleTimeout’=>3600));
!37
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Or use stateless mode
• In stateless mode, no jobs are created besides database jobs • It’s the simplest way to connect to the toolkit • Use a persistent connection (parameter 5 = true) for speed
‣ You can also pass in an existing persistent connection (shown a few slides back)
require_once('ToolkitService.php'); $conn = ToolkitService::getInstance(‘*LOCAL’, ‘ALAN’, ‘ALANPW’, ‘ibm_db2’, true); // true = persistent connection $conn->setOptions(‘stateless’=>true)); // stateless is simple
!38
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Or use stateless mode
• In stateless mode, no jobs are created besides database jobs • It’s the simplest way to connect to the toolkit • Use a persistent connection (parameter 5 = true) for speed
‣ You can also pass in an existing persistent connection (shown a few slides back)
require_once('ToolkitService.php'); $conn = ToolkitService::getInstance(‘*LOCAL’, ‘ALAN’, ‘ALANPW’, ‘ibm_db2’, true); // true = persistent connection $conn->setOptions(‘stateless’=>true)); // stateless is simple
!39
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Reduce IFS reads/writes
!40
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
IFS not as robust as DB2
• IBM i reverses the normal dynamic § Database (DB2) is fast; stream file access (IFS) can be slower
• Depends on workload, how many files accessed § Not as important as reducing HTTP access or other network
activity, for example
• Here are several tips...
!41
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Tips to reduce IFS accesses
• Turn off or reduce logging to files in production ‣ Large log files can be a culprit on some systems
• Make files cacheable for long periods of time by setting “expires” headers (see Session 3 for more) ‣ https://httpd.apache.org/docs/current/mod/
mod_expires.html
• Use an opcode cache (see Optimizer+ discussion later in presentation)
• more on next slide
!42
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
More tips to reduce IFS accesses
• In the UNIX world, file access is called “stat”. Any tips for reducing IFS “stats” will be effective on IBM i
• Examples:
• In Apache, turn off checking for .htaccess files if you’re not using them, with “AllowOverride none” ‣ # disable htaccess checks <Directory /> AllowOverride none </Directory>
• Allow symbolic links ‣ Options +FollowSymLinks -SymLinksIfOwnerMatch ‣ Otherwise, Apache will make a separate call on each filename to
ensure it is not a symlink.
!43
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Zend Server config for speed
!44
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Zend Server for IBM i
• Download ‣ http://www.zend.com/en/products/server/downloads-ibmi
• Zend Server 9.x editions ‣ http://www.zend.com/en/products/server/editions-ibm-i ‣ Basic, Professional, Enterprise ‣ Same download, different license
• Professional and higher include the monitoring/tracing tools we’ll be discussing here
!45
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Make the most of OpCache
• OpCache: “opcode cache” that speeds PHP execution ‣ The first time a PHP script runs, OpCache stores the compiled
version in memory, speeding future runs
‣ Works well with its default settings
• What’s configurable? ‣ Amount of memory to allocate to OpCache ‣ Number of scripts to keep in memory ‣ Timestamp-checking interval ‣ How often to check if a script has been changed
• Next slide: details on the timestamp-checking interval
!46
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Timestamp checking by OpCache
• Timestamp validation frequency: how often OpCache will check if a script has been changed § Ensures you are not running stale code § Default: 2 seconds
• The default (2 secs) is usually OK • For max speed, disable timestamp validation via
admin GUI § Use in production only § Usually only a small improvement § But I’ve seen BIG improvement on systems with slow IFS access § Caution if you turn off timestamp validation:
• Changes to your app NOT applied till you clear optimizer cache • Good reason to keep timestamp validation on in development env.
!47
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Turn off unused PHP extensions
• Extensions provide extra functionality to PHP § Each one uses memory
• Many are enabled by default § Default: ibm_db2 is on, SQL Server is off § Turn off those that you do not use § Do not turn off extensions needed by Zend Server’s GUI
• See my blog for exact instructions § http://www.alanseiden.com/2011/08/08/php-performance-tip-
disable-unused-extensions-with-zend-server/
!48
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Cache it
!49
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Two types of cache
• Zend Data Cache ‣ Save any type of data as key/value pairs ‣ Available in all editions of Zend Server ‣ Good for saving query results or any data that you want to reuse
• Zend Page Cache ‣ Cache a whole page (URL) ‣ Examples: home page (not
personalized), JSON content for state or country codes (thatdon’t change often)
!50
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Zend Data Cache
• Save string or array data ‣ Similar to memcache
• APIs for shared memory and disk storage ‣ “shm” means shared memory. “disk” means disk ‣ zend_shm_cache_fetch(), zend_shm_cache_store() ‣ zend_disk_cache_fetch(), zend_disk_cache_store()
!51
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Zend Data Cache
• How to use the APIs ‣ Pass a key name, an object or string, and the “time to live”
number (optional) • boolean zend_shm_cache_store(string [namespace::]key, mixed var [, int ttl])
• Example: cache district number for 300 seconds • $success = zend_shm_cache_store(‘district’, ‘12345’, 300);
‣ Fetch with just the key name • mixed zend_shm_cache_fetch(string [namespace::]key)
• Example: retrieve district number • $district = zend_shm_cache_fetch(‘district’); // false if fails to fetch
• White paper with examples ‣ http://static.zend.com/topics/Zend-Server-Data-Caching-
Whitepaper-0106-T-WP-R1-EN.pdf
!52
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Zend Page Cache
• A premium feature of Zend Server • Set up URLs to cache via Zend Server’s GUI • Match exact URL or regular expression
!53
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Reduce Session Locking
!54
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
PHP session files remember info
• Can keep track of user who is logged in, for example ‣ Cookie in browser tells PHP which session file to use ‣ session_start() initiates session in PHP
• Opens and locks the file for updating ‣ Located in /tmp by default ‣ Access data via $_SESSION
array
!55
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
AJAX requests burden sessions
• With AJAX, one page is > 1 request • Multiple requests (AJAX/JSON) in one page • If PHP sessions used (session_start), all requests from one
browser use same PHP session on back-end
!56
• Numerous PHP requests launched in one page. Note the “waterfall” shape; each waits for the previous to finish
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Load test shows this session is slow
!57
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
View from performance data investigator
!58
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
DEQW everywhere
!59
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Locking found
!60
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Solution to AJAX session locking
!61
• As soon as your application finishes writing data to the session, close it • session_write_close() ends the lock
• You can still read $_SESSION array
• Comparison on next slide
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Without, and with, session_write_close()
!62
WITHOUT session_write_close()
WITH IT Parallel run, faster! e.g. 834ms instead of 1.84ms
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Go asynchronous
!63
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Premium features that can help
• Zend Job Queue offloads long-running processes to run asynchronously. Examples: § Sending an email message § Crunching large datasets § Sending data to a web service on another server § Creating PDF files
!64
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Job Queue is part of Zend Server
• Comes with Professional Edition and up • Web-based • See job status in Zend Server GUI • From the documentation: “Long-running report generation, order
processing, database cleanup, and pulling of RSS feeds are some examples of jobs that can be executed asynchronously. Zend Server for IBM i incorporates a job queue to provide full support for creating, executing and managing jobs to optimize application performance and reduce server load, minimizing application bottlenecks and improving the end-user experience. “
!65
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Special abilities of Zend Job Queue
• Move tasks into a separate execution queue § Off-load to new process, later time, or different server
• Execute certain tasks at a specified time § Schedule, optionally repeat at intervals
• Use complex parameters
• Do it from a PHP API or Zend Server GUI
• Launch faster than PHP-CLI
!66
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Creating Jobs
• Use createHttpJob() method
• Pass parameters § Simple: via query string $_GET § Complex: as an associative array of key => value pairs
• Set job options § Name, priority, schedule, etc. § Create deferred or recurring jobs
• Launch right from PHP or use the Zend Server UI
$queue = new ZendJobQueue(); $queue->createHttpJob('http://backend.local/jobs/
somejob.php');
!67
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
More about Zend Job Queue
Specs: http://files.zend.com/help/Zend-Server/jobqueue-global-api.html Tutorial: http://files.zend.com/help/Zend-Server/working_with_jobs.htm
API signature for createHttpJob: int ZendJobQueue::createHttpJob ( string $url, array $vars, mixed $options)
Example with nested array variables: $queue = new ZendJobQueue(); $queue->createHttpJob( ‘http://yourIBMi.com/send_alert.php’, array(‘from’=> ‘[email protected]’, ‘to’=>array(‘[email protected]’, ‘[email protected]’)), array(‘persistent’=>false) );
!68
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Job Queue Management
View job status and manage execution
!69
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Other Job Capabilities
l Managing priorities l Job dependencies l Querying for jobs l Checking job status and queue statistics l Suspending and resuming recurring jobs & queues l Passing custom HTTP headers l Management of jobs
l Handling failures and controlling retries l Code tracing, monitor
!70
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Job Queue Tip
l If task will run more than 60 seconds, increase the FastCGI request timeout
l /www/zendphp7/conf/fastcgi.conf ‣ Default: RequestTimeout="60"
• Otherwise you’ll get HTTP 408 errors and unpredictable results in the Job Queue GUI
• New in Zend Server 2018: manage long-running CLI jobs via Job Queue: https://www.itjungle.com/2018/09/10/zend-server-2018-brings-php-7-2-to-ibm-i/
!71
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
That’s part 2. Coming up next...
!72
Session 3: Ensure a fast user experience
Let your PHP apps fly on IBM i: High Performance PHP (Part 2)Alan Seiden Consulting
Contact and tips
Alan Seiden Seiden Group Ho-Ho-Kus, NJ
!73
[email protected] ● 201-447-2437 ● twitter: @alanseiden
Free newsletter: http://seidengroup.com/tips
CIO Summit information:[email protected]