Ensuring Technical Readiness For Copilot in Microsoft 365
Thread based development with PHP
1. PHP and Thread based development
September 2013
Sunday, September 22, 13
2. PHP and Thread based development
Schedule
What is a Thread
What do i need to work with Threads in PHP
Starting a simple Thread
Stack data using a Worker
Sharing data using a Stackable
Synchronize using a Mutex
Synchronize using a Closure
Stack your data on a Worker
Sharing resources
Problems you’ll face when working with Threads
Sunday, September 22, 13
3. What is a Thread
Procedure that runs independently from its main program
Threads typically exists as subsets of processes
Sunday, September 22, 13
4. What do i need to work with Threads
PHP 5.3+
compiled thread safe with --enable-maintainer-zts
PECL extension pthreads
or install runtime from http://appserver.io
Sunday, September 22, 13
5. Starting a simple Thread
Shows how a Thread will be created and started
That the script has been finished before the Thread has been finished
Sunday, September 22, 13
6. PHP and Thread based development
Starting a simple Thread
Sunday, September 22, 13
7. PHP and Thread based development
Starting a simple Thread - Result
Sunday, September 22, 13
8. Stack data using a Worker
Allows you to stack data and execute in a Thread
Works like a queue
Interesting to build a daemon e. g. a HTTP server ;)
Sunday, September 22, 13
9. PHP and Thread based development
Sharing data using a Stackable
Sunday, September 22, 13
10. PHP and Thread based development
Stacking data using a Worker - Result
Sunday, September 22, 13
11. Sharing data using a Stackable
Tasks that are executed by Worker threads
Enables you to share data between threads
Sunday, September 22, 13
12. PHP and Thread based development
Sharing data using a Stackable
Sunday, September 22, 13
13. PHP and Thread based development
Sharing data using a Stackable - Result
Sunday, September 22, 13
14. Synchronize using a Mutex
Can be used to prevent threads overwrite shared data
Sunday, September 22, 13
15. PHP and Thread based development
Synchronize using a Mutex
Sunday, September 22, 13
16. PHP and Thread based development
Starting a simple Thread - Result
Sunday, September 22, 13
17. Synchronize using a Closure
Necessary to influence Thread workflow
Allows starting/stopping a referenced Thread
Sunday, September 22, 13
18. PHP and Thread based development
Synchronize using a Closure
Sunday, September 22, 13
19. PHP and Thread based development
Synchronize using a Closure - Result
Sunday, September 22, 13
20. Sharing resources
Some resource types can be shared, e. g. sockets
Not all resources can be shared, e. g. MySQLi
Sunday, September 22, 13
21. PHP and Thread based development
Sharing resources
Sunday, September 22, 13
22. PHP and Thread based development
Sharing resources - Result
Sunday, September 22, 13
23. appserver.io, a reference
HTTP 1.1 compliant web server
Persistence Container supporting Doctrine
MessageQueue
Websocket Server based on Ratchet
Demo applications available: Neos, Magento ... more soon
Sunday, September 22, 13
24. PHP and Thread based development
Installation
as .pkg file on Mac OS X 10.8.x
as .deb for Debian 7.x + Ubuntu 12.04
Debian Repository http://deb.appserver.io
Sunday, September 22, 13
25. PHP and Thread based development
Website
Sunday, September 22, 13