PHP Accelerator: Difference between revisions
No edit summary |
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight" |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
[[Image:Preferences-system-performance.svg|200px|frameless|right]] | |||
A [[wp:PHP_accelerator|PHP Acelerator]] is a tool that will enhance the [[Performance_tuning|performance]] of web applications written for the PHP scripting language. The free [http://php.net/apc Alternative PHP Cache] (APC) is distributed as a PEAR package. | A [[wp:PHP_accelerator|PHP Acelerator]] is a tool that will enhance the [[Performance_tuning|performance]] of web applications written for the PHP scripting language. The free [http://php.net/apc Alternative PHP Cache] (APC) is distributed as a PEAR package. | ||
| Line 7: | Line 8: | ||
== Installation == | == Installation == | ||
Assuming you already have Apache2 and PHP5 (with dev extensions so PECL can run phpize), it's as easy as | Assuming you already have Apache2 and PHP5 (with dev extensions so PECL can run phpize), it's as easy as | ||
< | <syntaxhighlight lang="bash"> | ||
# make sure we have the development headers and apxs2 binary for threaded versions of apache2 | # make sure we have the development headers and apxs2 binary for threaded versions of apache2 | ||
sudo apt-get install apache2-threaded-dev | sudo apt-get install apache2-threaded-dev | ||
| Line 23: | Line 24: | ||
cd /var/www | cd /var/www | ||
sudo ln -s /usr/share/php/apc.php | sudo ln -s /usr/share/php/apc.php | ||
</ | </syntaxhighlight> | ||
== MediaWiki == | == MediaWiki == | ||
MediaWiki can take advantage of the APC cache if you tell it to. | MediaWiki can take advantage of the APC cache if you tell it to. | ||
see [[mw:Manual:Configuration_settings#Cache|The Manual for cache settings]], and set [[mw:Manual:$wgMainCacheType]] in LocalSettings.php: | see [[mw:Manual:Configuration_settings#Cache|The Manual for cache settings]], and set [[mw:Manual:$wgMainCacheType]] in LocalSettings.php: | ||
< | <syntaxhighlight lang="php"> | ||
$wgMainCacheType = CACHE_ACCEL; | $wgMainCacheType = CACHE_ACCEL; | ||
</ | </syntaxhighlight> | ||
== Troubleshooting == | == Troubleshooting == | ||
If you notice sluggishness in your site after installing APC, then check out the front-end (apc.php). The sure sign that you need to increase your cache size is that the "cache full" count is greater than one. | If you notice sluggishness in your site after installing APC, then check out the front-end (apc.php). The sure sign that you need to increase your cache size is that the "cache full" count is greater than one. | ||
[[Image:Apc-problems.png|200px|thumb|right|Cache is too small]] | [[Image:Apc-problems.png|200px|thumb|right|Cache is too small]] | ||
# [[Performance_tuning|Check your memory]] | # [[Performance_tuning|Check your memory]] | ||
# Increase the Shared Memory Size for APC in your php.ini file e.g. <code>apc.shm_size = 128</code> | # Increase the Shared Memory Size for APC in your php.ini file e.g. <code>apc.shm_size = 128</code> | ||
# Restart Apache | # Restart Apache | ||
# Use the Apache Bench tool to test performance with and without APC enabled. | # Use the Apache Bench tool to test performance with and without APC enabled. | ||
| Line 50: | Line 51: | ||
The graphs were produced using '''ab''' and '''gnuplot''' ab is Apache Bench, a benchmarking and stress-testing tool. Using -g to produce CSV output suitable for feeding to spreadsheets or gnuplot, you can generate the graphs. | The graphs were produced using '''ab''' and '''gnuplot''' ab is Apache Bench, a benchmarking and stress-testing tool. Using -g to produce CSV output suitable for feeding to spreadsheets or gnuplot, you can generate the graphs. | ||
< | <syntaxhighlight lang="bash"> | ||
ab -g ~/ab-without-apc.csv -n 50 -c 1 http://freephile.com/wiki/index.php/Main_Page | ab -g ~/ab-without-apc.csv -n 50 -c 1 http://freephile.com/wiki/index.php/Main_Page | ||
</ | </syntaxhighlight> | ||
produces this output: | produces this output: | ||
<pre> | <pre> | ||
| Line 82: | Line 83: | ||
Connection Times (ms) | Connection Times (ms) | ||
min mean[+/-sd] median max | |||
Connect: 1 1 0.1 1 2 | Connect: 1 1 0.1 1 2 | ||
Processing: 515 604 113.4 567 1030 | Processing: 515 604 113.4 567 1030 | ||
| Line 89: | Line 90: | ||
Percentage of the requests served within a certain time (ms) | Percentage of the requests served within a certain time (ms) | ||
50% 568 | |||
66% 600 | |||
75% 608 | |||
80% 644 | |||
90% 734 | |||
95% 925 | |||
98% 1031 | |||
99% 1031 | |||
100% 1031 (longest request) | |||
</pre> | </pre> | ||
| Line 122: | Line 123: | ||
[[Category:PHP]] | [[Category:PHP]] | ||
[[Category:Wiki]] | [[Category:Wiki]] | ||
[[Category: | [[Category:SysAdmin]] | ||
[[Category:Performance]] | |||