README 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. Introduction
  2. ============
  3. LiteSpeed SAPI module is a dedicated interface for PHP integration with
  4. LiteSpeed Web Server. LiteSpeed SAPI has similar architecture to the
  5. FastCGI SAPI with there major enhancements: better performance, dynamic
  6. spawning and PHP configuration modification through web server
  7. configuration and .htaccess files.
  8. Our simple benchmark test ("hello world") shows that PHP with
  9. LiteSpeed SAPI has 30% better performance over PHP with FastCGI SAPI,
  10. which is nearly twice the performance that Apache mod_php can deliver.
  11. A major drawback of FastCGI PHP comparing to Apache mod_php is lacking
  12. the flexibilities in PHP configurations. PHP configurations cannot be
  13. changed at runtime via configuration files like .htaccess files or web
  14. server's virtual host configuration. In shared hosting environment,
  15. each hosting account will has its own "open_basedir" overridden in
  16. server configuration to enhance server security when mod_php is used.
  17. usually, FastCGI PHP is not an option in shared hosting environment
  18. due to lacking of this flexibility. LiteSpeed SAPI is carefully designed
  19. to address this issue. PHP configurations can be modified the same way
  20. as that in mod_php with the same configuration directives.
  21. PHP with LiteSpeed SAPI is highly recommended over FastCGI PHP for
  22. PHP scripting with LiteSpeed web server.
  23. Building PHP with LiteSpeed SAPI
  24. ================================
  25. You need to add "--with-litespeed" to the configure command to build
  26. PHP with LiteSpeed SAPI, all other SAPI related configure options
  27. should be removed.
  28. For example:
  29. ./configure --with-litespeed
  30. make
  31. You should find an executable called 'php' under sapi/litespeed/
  32. directory after the compilation succeeds. Copy it to
  33. 'lsws/fcgi-bin/lsphp' or wherever you prefer, if LiteSpeed web server
  34. has been configured to run PHP with LiteSpeed SAPI already, you just
  35. need to overwrite the old executable with this one and you are all
  36. set.
  37. Start PHP from command line
  38. ===========================
  39. Usually, lsphp is managed by LiteSpeed web server in a single server
  40. installation. lsphp can be used in clustered environment with one
  41. LiteSpeed web server at the front, load balancing lsphp processes
  42. running on multiple backend servers. In such environment, lsphp can be
  43. start manually from command with option "-b <socket_address>", socket
  44. address can be IPv4, IPv6 or Unix Domain Socket address.
  45. for example:
  46. ./lsphp -b [::]:3000
  47. have lsphp bind to port 3000 on all IPv4 and IPv6 address,
  48. ./lsphp -b *:3000
  49. have lsphp bind to port 300 on all IPv4 address.
  50. ./lsphp -b 192.168.0.2:3000
  51. have lsphp bind to address 192.168.0.2:3000.
  52. ./lsphp -b /tmp/lsphp_manual.sock
  53. have lsphp accept request on Unix domain socket "/tmp/lsphp_manual.sock"
  54. Using LiteSpeed PHP with LiteSpeed Web Server
  55. =============================================
  56. Detailed information about how to configure LiteSpeed web server with
  57. PHP support is available from our website, at:
  58. http://www.litespeedtech.com/docs/HowTo_QA.html
  59. Usually, PHP support has been configured out of box, you don't need to
  60. change it unless you want to change PHP interface from FastCGI to
  61. LiteSpeed SAPI or vice versa.
  62. Brief instructions are as follow:
  63. 1) Login to web administration interface, go to 'Server'->'Ext App' tab,
  64. add an external application of type "LSAPI app", "Command" should be
  65. set to a shell command that executes the PHP binary you just built.
  66. "Instances" should be set to "1". Add "LSAPI_CHILDREN" environment
  67. variable to match the value of "Max Connections". More tunable
  68. environment variable described below can be added.
  69. 2) Go to 'Server'->'Script Handler' tab, add a script handler
  70. configuration: set 'suffix' to 'php', 'Handler Type' to 'LiteSpeed
  71. API', 'Handler Name' should be the name of external application
  72. just defined.
  73. 3) Click 'Apply Changes' link on the top left of the page, then click
  74. 'graceful restart'. Now PHP is running with LiteSpeed SAPI.
  75. Tunings
  76. -------
  77. There are a few environment variables that can be tweaked to control the
  78. behavior of LSAPI application.
  79. * LSAPI_CHILDREN or PHP_LSAPI_CHILDREN (default: 0)
  80. There are two ways to let PHP handle multiple requests concurrently,
  81. Server Managed Mode and Self Managed Mode. In Server Managed Mode,
  82. LiteSpeed web server dynamically spawn/stop PHP processes, in this mode
  83. "Instances" should match "Max Connections" configuration for PHP
  84. external application. To start PHP in Self Managed Mode, "Instances"
  85. should be set to "1", while "LSAPI_CHILDREN" environment variable should
  86. be set to match the value of "Max Connections" and >1. Web Server will
  87. start one PHP process, this process will start/stop children PHP processes
  88. dynamically based on on demand. If "LSAPI_CHILDREN" <=1, PHP will be
  89. started in server managed mode.
  90. Self Managed Mode is preferred because all PHP processes can share one
  91. shared memory block for the opcode cache.
  92. Usually, there is no need to set value of LSAPI_CHILDREN over 100 in
  93. most server environment.
  94. * LSAPI_AVOID_FORK (default: 0)
  95. LSAPI_AVOID_FORK specifies the policy of the internal process manager in
  96. "Self Managed Mode". When set to 0, the internal process manager will stop
  97. and start children process on demand to save system resource. This is
  98. preferred in a shared hosting environment. When set to 1, the internal
  99. process manager will try to avoid freqently stopping and starting children
  100. process. This might be preferred in a dedicate hosting environment.
  101. * LSAPI_EXTRA_CHILDREN (default: 1/3 of LSAPI_CHILDREN or 0)
  102. LSAPI_EXTRA_CHILDREN controls the maximum number of extra children processes
  103. can be started when some or all existing children processes are in
  104. malfunctioning state. Total number of children processes will be reduced to
  105. LSAPI_CHILDREN level as soon as service is back to normal.
  106. When LSAPI_AVOID_FORK is set to 0, the default value is 1/3 of
  107. LSAPI_CHIDLREN, When LSAPI_AVOID_FORK is set to 1, the default value is 0.
  108. * LSAPI_MAX_REQS or PHP_LSAPI_MAX_REQUESTS (default value: 10000)
  109. This controls how many requests each child process will handle before
  110. it exits automatically. Several PHP functions have been identified
  111. having memory leaks. This parameter can help reducing memory usage
  112. of leaky PHP functions.
  113. * LSAPI_MAX_IDLE (default value: 300 seconds)
  114. In Self Managed Mode, LSAPI_MAX_IDLE controls how long a idle child
  115. process will wait for a new request before it exits. This option help
  116. releasing system resources taken by idle processes.
  117. * LSAPI_MAX_IDLE_CHILDREN
  118. (default value: 1/3 of LSAPI_CHILDREN or LSAPI_CHILDREN)
  119. In Self Managed Mode, LSAI_MAX_IDLE_CHILDREN controls how many idle
  120. children processes are allowed. Excessive idle children processes
  121. will be killed by the parent process immediately.
  122. When LSAPI_AVOID_FORK is set to 0, the default value is 1/3 of
  123. LSAPI_CHIDLREN, When LSAPI_AVOID_FORK is set to 1, the default value
  124. is LSAPI_CHILDREN.
  125. * LSAPI_MAX_PROCESS_TIME (default value: 300 seconds)
  126. In Self Managed Mode, LSAPI_MAX_PROCESS_TIME controls the maximum
  127. processing time allowed when processing a request. If a child process
  128. can not finish processing of a request in the given time period, it
  129. will be killed by the parent process. This option can help getting rid
  130. of dead or runaway child process.
  131. * LSAPI_PGRP_MAX_IDLE (default value: FOREVER )
  132. In Self Managed Mode, LSAPI_PGRP_MAX_IDLE controls how long the parent
  133. process will wait before exiting when there is no child process.
  134. This option help releasing system resources taken by an idle parent
  135. process.
  136. * LSAPI_PPID_NO_CHECK
  137. By default a LSAPI application check the existence of its parent process
  138. and exits automatically if the parent process died. This is to reduce
  139. orphan process when web server is restarted. However, it is desirable
  140. to disable this feature, such as when a LSAPI process was started
  141. manually from command line. LSAPI_PPID_NO_CHECK should be set when
  142. you want to disable the checking of existence of parent process.
  143. When PHP started by "-b" option, it is disabled automatically.
  144. Compatibility with Apache mod_php
  145. =================================
  146. LSAPI PHP supports PHP configuration overridden via web server configuration
  147. as well as .htaccess.
  148. Since 4.0 release "apache_response_headers" function is supported.
  149. Contact
  150. =======
  151. For support questions, please post to our free support forum, at:
  152. http://www.litespeedtech.com/forum/
  153. For bug report, please send bug report to bug [at] litespeedtech.com.