We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

OPcached PHP Frameworks perform better than Phalcon?

Hi all,

I've created a simple "Hello World" application with Phalcon, CodeIgniter, and my own PHP framework to run performance benchmaks and both of PHP frameworks performed much faster than Phalcon.

They all have no complex setups (IndexController->indexAction() that simply displays "Hello World" in view) and I run Apache Bench, just like the document explains (2,000 requests with 10 concurrent requests each). The only difference is that I used OPcache instead of APC. My machine is MacBook Pro 15" Retina (2.7 GHz Intel Core i7 with 16GB 1600 Mhz DDR3) and all of the applications were installed from Homebrew (PHP 5.5 with Phalcon).

Has anyone tried a similar test and got the same result?

Is there a way to make Phalcon faster like OPcached PHP frameworks?



8.1k
edited Jun '14

Wow, what's with all the downvoting? (Zealotry?)

If in your tests Phalcon is truly (much) slower, I am certainly interested in this?

btw; what do you mean with OPcached frameworks? OPcache is enabled or it isn't right? So I assume you also tested Phalcon with OPcache enabled?

I have no idea why everyone is giving me the negative votes without leaving any comments (but I don't care. Everyone has different opinions.)

Don't give me wrong, I like Phalcon. It's clean, easy to setup, and very fast. (and I don't like most of the PHP frameworks because they are too messy and hard to setup.)

I just wanted to know if someone else has done the same thing and got the similar result.

Here are the results from Apache Bench.

"Hello World" CodeIgniter with no Opcache extension

$ ab -n 2000 -c 10 https://localhost/codeigniter/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        Apache/2.2.27
Server Hostname:        localhost
Server Port:            80

Document Path:          /codeigniter/index.php
Document Length:        67 bytes

Concurrency Level:      10
Time taken for tests:   10.455 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      580000 bytes
HTML transferred:       134000 bytes
Requests per second:    191.29 [#/sec] (mean)
Time per request:       52.277 [ms] (mean)
Time per request:       5.228 [ms] (mean, across all concurrent requests)
Transfer rate:          54.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:    32   52   9.6     51     137
Waiting:       31   52   9.6     51     137
Total:         32   52   9.5     51     137

Percentage of the requests served within a certain time (ms)
  50%     51
  66%     53
  75%     54
  80%     55
  90%     58
  95%     62
  98%     91
  99%    100
 100%    137 (longest request)

"Hello World" Phalcon with no Opcache extension

$ ab -n 2000 -c 10 https://localhost/phalcon/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        Apache/2.2.27
Server Hostname:        localhost
Server Port:            80

Document Path:          /phalcon/index.php
Document Length:        168 bytes

Concurrency Level:      10
Time taken for tests:   4.150 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      814000 bytes
HTML transferred:       336000 bytes
Requests per second:    481.98 [#/sec] (mean)
Time per request:       20.748 [ms] (mean)
Time per request:       2.075 [ms] (mean, across all concurrent requests)
Transfer rate:          191.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     9   21   9.6     19      90
Waiting:        9   20   9.6     19      90
Total:          9   21   9.6     19      90

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     20
  75%     21
  80%     21
  90%     23
  95%     24
  98%     72
  99%     78
 100%     90 (longest request)

Phalcon is much faster than CodeIgniter without Opcache extension.

"Hello World" CodeIgniter with Opcache extension

$ ab -n 2000 -c 10 https://localhost/codeigniter/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        Apache/2.2.27
Server Hostname:        localhost
Server Port:            80

Document Path:          /codeigniter/index.php
Document Length:        67 bytes

Concurrency Level:      10
Time taken for tests:   0.452 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      580000 bytes
HTML transferred:       134000 bytes
Requests per second:    4429.53 [#/sec] (mean)
Time per request:       2.258 [ms] (mean)
Time per request:       0.226 [ms] (mean, across all concurrent requests)
Transfer rate:          1254.46 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.2      0      52
Processing:     1    2   3.4      2      53
Waiting:        1    2   3.4      1      53
Total:          1    2   3.6      2      54

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      3
  95%      3
  98%      4
  99%      4
 100%     54 (longest request)

"Hello World" Phalcon with Opcache extension

$ ab -n 2000 -c 10 https://localhost/phalcon/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        Apache/2.2.27
Server Hostname:        localhost
Server Port:            80

Document Path:          /phalcon/index.php
Document Length:        168 bytes

Concurrency Level:      10
Time taken for tests:   1.872 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      814000 bytes
HTML transferred:       336000 bytes
Requests per second:    1068.57 [#/sec] (mean)
Time per request:       9.358 [ms] (mean)
Time per request:       0.936 [ms] (mean, across all concurrent requests)
Transfer rate:          424.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     4    9   2.3      9      28
Waiting:        4    9   2.3      9      28
Total:          4    9   2.3      9      28

Percentage of the requests served within a certain time (ms)
  50%      9
  66%     10
  75%     10
  80%     10
  90%     11
  95%     13
  98%     14
  99%     22
 100%     28 (longest request)

As you can see, CodeIgniter with Opcache extension is much faster than Phalcon with Opcache extension.

I'm using Homebrew php55 and php55-phalcon on Mac OS X 10.7.5.

php --version
PHP 5.5.12 (cli) (built: May  9 2014 14:03:50) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies


8.1k
edited Jun '14

Thanks for posting your results. I don't know what could explain the difference, but it would be interesting to hear something from a dev or someone who has perhaps experience in the matter.. :)

I'm interested too, here are some questions:

  • can you share the code you used?
  • did you try to run the code at least twice with opcache enabled?
  • can you try with another test tool like wrk (https://github.com/wg/wrk or brew install wrk)

Hi Max,

Actually not much to share because I really didn't change that much.

For CodeIgniter, just download it from the website, unzip it, copy the files into codeigniter directory, and edit the application/views/welcome_message.php to display "Hello World" HTML. That's it.

For Phalcon, I used Phalcon devtool to generate a project, edit the app/config/services.php to remove everyting except url and view from $di because I don't use them, and edit the app/views/index/index.volt to display "Hello World" HTML. That's all.

I did run multiple tests but same results.

I'll try wrk later. It's not hard to setup, so you can try and let me know the result too.

By the way, CodeIgniter is still not my choice because I don't like the architecture.

OPcache saves the bytecode result of interpreting that PHP code on execution, so that the application doesn't have to be interpreted every time its executed. The crux of Phalcon is that the core of its framework is compiled as C so that it executes faster at runtime. All things being equal, if the bytecode is being cached, it doesn't matter if the phalcon is being compiled as C because the code is not being interpreted every time it executes, the application is simply executing the machine code that it had already cached; so what you're left comparing in the efficiency of the machine code artifacts to be executed per request. Really the speed gains of Phalcon only shine when you're not using Opcache, APC or HHVM JIT. That's not to say that Phalcon is bad, but I think people have these really weird expectations because they don't understand modern dynamic language methods of JIT and bytecode caching.