PHP, Handle with care

3,691 views
3,618 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,691
On SlideShare
0
From Embeds
0
Number of Embeds
1,708
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

PHP, Handle with care

  1. 1. PHP, Handle with Care PBWEB.CO.UK @PHILL_BROWN
  2. 2. What is a PHP Handler?<?php Interprets Helloecho ‘Hello’; code
  3. 3. It began with CGI
  4. 4. CGIWeb server PHP
  5. 5. Phoning for a taxi
  6. 6. CGI• Runs PHP on every request• High CPU• Doesn’t support PHP accelerators eg APC• Has security issues
  7. 7. An improvement: mod_suphp
  8. 8. Apache changes the PHP process owner
  9. 9. mod_suPHP mod_suPHP starts PHP via CGI mod_suPHPApache PHP changes process uid
  10. 10. Choosing your driver
  11. 11. Site 1cache 757includes 755themes 755Site 2cacheincludesthemes 757 755 755 Without Apache writableSite 3cache 757includes 755themes 755
  12. 12. Site 1cache 755includes 755 Running as filethemes 755 ownerSite 2cache 755includes 755themes 755 Apache writableSite 3cache 755includes 755themes 755
  13. 13. Site 1cache 775includes 755 Locking down eventhemes 755Site 2cacheincludesthemes 755 755 755 further Apache writableSite 3cache 755includes 755themes 755
  14. 14. Create Apache users and site groups Site1Group Site1User Site1Apache
  15. 15. drwxrwxr-x Site1User Site1Group cachedrwxr-xr-x Site1User Site1Group includesdrwxr-xr-x Site1User Site1Group theme
  16. 16. A different approach: mod_php
  17. 17. mod_phpApache Interprets PHP internally
  18. 18. Taking your own car
  19. 19. mod_php• Preloads PHP environment• Runs as Apache child process = low CPU• Shared memory• Supports bytecaching
  20. 20. mod_php• Un-scalable across multiple servers• Can fill up Apache queue = refused requests• Runs as a single user
  21. 21. mod_ruid2 - suphp’s better half
  22. 22. mod_php + mod_ruid2Apache mod_php mod_ruid2 Change process uid
  23. 23. Your own chauffeur
  24. 24. FastCGI - nu school
  25. 25. FastCGI Runs PHP in aWeb server FCGI server persistent FastCGI process
  26. 26. Being at a taxi rank LOADSOF TAXIS
  27. 27. FastCGI• Separates PHP from static requests• Uses persistent processes• Highly configurable• Lower CPU but higher memory usage
  28. 28. Benefit of separation Client Request static HTML PHPInternal HTTP FCGI server server
  29. 29. FastCGI Process Manager: adaptable process spawning
  30. 30. Summary CGI suPHP DSO ruid2 fCGI FPMCPU usageSupports PHP AcceleratorsRun as file ownerSeparation of interpreter andserverServer agnosticMemory usage
  31. 31. Handling questions.. Intensive processing ProbableQuestion? Phill memory leak ask PBWEB.CO.UK @PHILL_BROWN

×