PHP: APC Configuration and Usage Tips and Tricks Part 4

This PHP APC guide is divided on four different section:
1. PHP APC Configuration
2. Enable PHP APC Statistics
3. Howto Use PHP APC User Cache
4. PHP APC Performance Testing

4. PHP APC Performance Testing

This is very simple performance test setup just show that how powerful and important APC or any other Opcode Cache is. This test was carried out on CentOS 6.2 box, using APC 3.1.10, PHP 5.3.14 and Nginx 1.2.2.

4.1 Test Files on Web Server

Two files test.php and test_include.php, basic idea is just include test_include.php file 50 000 times and check how long it takes.
test.php


<?php

     	$start = microtime(true);

        for ($i = 0; $i < 50000; $i++) {
                include('test_include.php');
        }

	$end = microtime(true);

        echo "Start: " . $start . "
"; echo "End: " . $end . "
"; echo "Diff: ". ($end-$start) . "
"; ?>

test_include.php


<?php

     	$t =    "Lorem ipsum dolor sit amet, consectetur
                adipiscing elit. Cras non odio dolor,
                eget fermentum ligula. Nunc et risus at
                augue sollicitudin varius. Suspendisse
                vel mauris lacus, ac egestas mauris.
                Suspendisse dignissim massa id ligula
                scelerisque luctus. Etiam lobortis nisl
                lorem. Integer non velit ante. Nulla
                molestie consequat varius. Proin feugiat,
                tortor nec feugiat vestibulum, nisl odio
                aliquet est, in mollis sapien massa vitae
                ipsum. Cras volutpat nisi at metus
                volutpat at adipiscing ante pulvinar.
                Curabitur semper mauris risus. Aliquam non
                nunc eu nibh tincidunt condimentum aliquet
                eu magna. Sed lobortis consequat lorem a
                pellentesque. Ut vel odio sit amet elit
                porta pellentesque. Aliquam erat volutpat.";

?>

4.2 Performance Test Results

APC Cache Disabled:
Start: 1326635645.6191
End: 1326635669.8046
Diff: 24.185463905334

APC Cache Enabled:
Start: 1326635808.3951
End: 1326635810.2877
Diff: 1.8925409317017

Difference is huge. With APC Cache disabled same script took 24.19 seconds and with APC Cache enabled it took only 1.89 seconds.

This PHP APC guide is divided on four different section:
1. PHP APC Configuration
2. Enable PHP APC Statistics
3. Howto Use PHP APC User Cache
4. PHP APC Performance Testing

40 comments on “PHP: APC Configuration and Usage Tips and Tricks Part 4

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close