Download - Thread based development with PHP
![Page 1: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/1.jpg)
PHP and \Thread based development
September 2013
Sunday, September 22, 13
![Page 2: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/2.jpg)
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
![Page 3: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/3.jpg)
What is a \ThreadProcedure that runs independently from its main program
Threads typically exists as subsets of processes
Sunday, September 22, 13
![Page 4: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/4.jpg)
What do i need to work with \ThreadsPHP 5.3+
compiled thread safe with --enable-maintainer-zts
PECL extension pthreads
or install runtime from http://appserver.io
Sunday, September 22, 13
![Page 5: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/5.jpg)
Starting a simple \ThreadShows how a \Thread will be created and started
That the script has been finished before the Thread has been finished
Sunday, September 22, 13
![Page 6: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/6.jpg)
PHP and \Thread based development
Starting a simple \Thread
Sunday, September 22, 13
![Page 7: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/7.jpg)
PHP and \Thread based development
Starting a simple \Thread - Result
Sunday, September 22, 13
![Page 8: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/8.jpg)
Stack data using a \WorkerAllows 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
![Page 9: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/9.jpg)
PHP and \Thread based development
Sharing data using a \Stackable
Sunday, September 22, 13
![Page 10: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/10.jpg)
PHP and \Thread based development
Stacking data using a \Worker - Result
Sunday, September 22, 13
![Page 11: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/11.jpg)
Sharing data using a \StackableTasks that are executed by \Worker threads
Enables you to share data between threads
Sunday, September 22, 13
![Page 12: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/12.jpg)
PHP and \Thread based development
Sharing data using a \Stackable
Sunday, September 22, 13
![Page 13: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/13.jpg)
PHP and \Thread based development
Sharing data using a \Stackable - Result
Sunday, September 22, 13
![Page 14: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/14.jpg)
Synchronize using a \MutexCan be used to prevent threads overwrite shared data
Sunday, September 22, 13
![Page 15: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/15.jpg)
PHP and \Thread based development
Synchronize using a \Mutex
Sunday, September 22, 13
![Page 16: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/16.jpg)
PHP and \Thread based development
Starting a simple \Thread - Result
Sunday, September 22, 13
![Page 17: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/17.jpg)
Synchronize using a \ClosureNecessary to influence \Thread workflow
Allows starting/stopping a referenced \Thread
Sunday, September 22, 13
![Page 18: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/18.jpg)
PHP and \Thread based development
Synchronize using a \Closure
Sunday, September 22, 13
![Page 19: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/19.jpg)
PHP and \Thread based development
Synchronize using a \Closure - Result
Sunday, September 22, 13
![Page 20: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/20.jpg)
Sharing resourcesSome resource types can be shared, e. g. sockets
Not all resources can be shared, e. g. MySQLi
Sunday, September 22, 13
![Page 21: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/21.jpg)
PHP and \Thread based development
Sharing resources
Sunday, September 22, 13
![Page 22: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/22.jpg)
PHP and \Thread based development
Sharing resources - Result
Sunday, September 22, 13
![Page 23: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/23.jpg)
appserver.io, a referenceHTTP 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
![Page 24: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/24.jpg)
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
![Page 25: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/25.jpg)
PHP and \Thread based development
Website
Sunday, September 22, 13
![Page 26: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/26.jpg)
More information ...https://github.com/krakjoe/pthreads
https://computing.llnl.gov/tutorials/pthreads/
http://appserver.io
https://github.com/techdivision/TechDivision_ApplicationServer
http://www.slideshare.net/wagner_tim78/thread-based-development-with-php
http://tinyurl.com/na5ulal
Sunday, September 22, 13
![Page 27: Thread based development with PHP](https://reader033.vdocument.in/reader033/viewer/2022060201/5599c3c51a28abe2168b47a7/html5/thumbnails/27.jpg)
PHP and \Thread based development
Tim WagnerTechDivision GmbHSpinnereiinsel 3a83059 Kolbermoor
+49 8031 / 221055-0 +49 8031 / 221055-22 [email protected]
www.techdivision.com
Thanks!
Sunday, September 22, 13