There are a lot of tools available that can make developers life easier. Zend Server is one of them. The Zend products have come from a long way, but since the introduction of Zend Server the focus is more on a developers perspective than ever. The integrated tools make debugging, performance tuning, process offloading and deployment really accessible. Even extending it with your own needs is possible nowadays. The current PHP ecosystem gives every developer enormous amounts of power in creating applications without writing a lot of code.
In this talk I will show you how Zend Server can help you understand your own PHP application better, by using its tools to open the blackbox that your PHP application really is. This talk is not about selling Zend Server, but helping developers understand why reconsidering your development stack is always an option. Because in the end every developer likes to be a lazy developer.
51. MOVE SLOW REQUEST INTO JOB
$app->get('/slowrequest', function() use($app) {
$queue = new ZendJobQueue();
$queue->createHttpJob('/sendemail', array(
'email'=>'jeroen@enrise.com'),
array('name'=>'Send email')
);
return $app->json(array('That wasn't slow'));
});
$app->post('/sendemail', function() use ($app) {
sleep(5);
$params = ZendJobQueue::getCurrentJobParams();
ZendJobQueue::setCurrentJobStatus(ZendJobQueue::OK);
$response = new Response();
$response->headers->set('X-Info', 'mail send to '. $params['email']);
return $response;
});
52.
53. SECURING JOB ACTIONS
/**
* See Matthew Weier O'Phinney his blog serie about
* Zend Server
*
* https://mwop.net/blog/2014-09-04-zend-server-deployment-
* part-4.html
*/
if (! ZendJobQueue::getCurrentJobId()) {
header('HTTP/1.1 403 Forbidden');
exit(1);
}
55. AS SOON AS POSSIBLE
$queue = new ZendJobQueue();
// send the as soon as possible
$queue->createHttpJob('/sendemail',
array('email'=>'jeroen@enrise.com'),
array(
'name'=>'Send email',
'priority' => ZendJobQueue::PRIORITY_URGENT
)
);
56. AT A SPECIFIC TIME
$queue = new ZendJobQueue();
// send the email tomorrow 2am
$queue->createHttpJob('/sendemail',
array('email'=>'jeroen@enrise.com'),
array(
'name'=>'Send email',
'schedule_time' => date('Y-m-d h:i:s',
strtotime('tomorrow 2am'))
)
);
57. RECURRING
$queue = new ZendJobQueue();
// send the email every Monday at 2am
$queue->createHttpJob('/sendemail',
array('email'=>'jeroen@enrise.com'),
array(
'name'=>'Send email',
'schedule' => '0 2 * * 1'
)
);