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

PHP, Handle with care

3,281

Published on

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

No Downloads
Views
Total Views
3,281
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "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

×