create account

Add cache for Phalcon [Benchmark of php frameworks v0.0.6] by semasping

View this thread on: hive.blogpeakd.comecency.com
· @semasping · (edited)
$85.72
Add cache for Phalcon [Benchmark of php frameworks v0.0.6]
*[In Release 0.0.6](https://github.com/semasping/php_frameworks_for_tests/releases/tag/0.0.6):*
* Add new tests for phalcon:
  * Use Cache for load posts from DB in 'posts' most heavy page.
* Add posibility for viewing testing result of releseas
  * results for 0.0.5
  * results of testing release 0.0.6
### More informations about changes.
About cache and eager loading in laravel, I wrote in my previews post.
Now we add caching functional on page 'posts' in phalcon framework.
Let`s add new Controller:  

`PostwsController() in phalcon-3.2/app/controllers/PostswcController.php`

```
use Phalcon\Cache\Backend\File as BackFile;
use Phalcon\Cache\Frontend\Data as FrontData;
/**
 * Index action
 */
public function indexAction()
{
    $posts = null;
    $frontCache = new FrontData(
        [
            'lifetime' => 172800,
        ]
    );
    $cache = new BackFile(
        $frontCache,
        [
            'cacheDir' => '../app/cache/',
        ]
    );

    $cacheKey = 'posts.cache';

    $posts = $cache->get($cacheKey);

    if ($posts === null) {

        $this->persistent->parameters = null;
        $parameters = $this->persistent->parameters;
        if (!is_array($parameters)) {
            $parameters = [];
        }
        //$parameters["limit"] = "100";
        //$parameters["limit"] = array('number' => 100, 'offset' => 10);
        $parameters["order"] = "id";

        $posts = Posts::find($parameters);
        $cache->save($cacheKey, $posts);
    }

 if (count($posts) == 0) {
  $this->flash->notice("The search did not find any posts");

  $this->dispatcher->forward([
   "controller" => "postsCache",
   "action" => "index"
  ]);

  return;
 }
    //var_dump($posts);
 $this->view->posts = $posts;
}

```

Views we can copy from posts to postswc:
```
phalcon-3.2/app/views/layouts/posts.phtml -> phalcon-3.2/app/views/layouts/postswc.phtml
folder phalcon-3.2/app/views/posts -> folder phalcon-3.2/app/views/postswc
```

And that`s all. New page 'postswc' we can see by link [](http://php-frameworks.semasping.info/phalcon-3.2/public/postswc)

After tests we see that adding a cache did not change the situation. In table `!!phalcon-postswc` row.
|framework          |requests per second|relative|peak memory|relative|
|-------------------|------------------:|-------:|----------:|-------:|
|phalcon-index      |             113.17| 2,829.3|       0.49|     1.0|
|phalcon-authors    |              22.35|   558.8|       0.61|     1.3|
|phalcon-categories |              13.61|   340.3|       0.62|     1.3|
|laravel-index      |               8.67|   216.8|       6.21|    12.7|
|laravel-posts-el-cache|               8.00|   200.0|       7.34|    15.1|
|laravel-posts-el   |               7.79|   194.8|       7.34|    15.1|
|laravel-categories |               6.97|   174.3|       7.59|    15.6|
|laravel-authors    |               6.90|   172.5|       7.34|    15.1|
|!! phalcon-postswc    |               0.10|     2.5|       2.45|     5.0|
|phalcon-posts      |               0.09|     2.3|       2.36|     4.8|
|laravel-posts      |               0.04|     1.0|      15.13|    31.0|
|laravel-posts-cache|               0.04|     1.0|      18.46|    37.9|

![006screenshot-php-frameworks.semasping.info 2018-01-29 20-43-59-307.png](https://steemitimages.com/DQme6B99o1s4f8LpKMfXnHWSc3AcroAShYSgT5PdAtgfNHm/006screenshot-php-frameworks.semasping.info%202018-01-29%2020-43-59-307.png)


##### I'll tell you about adding  `eager loading` next time, because there is not `eager loading`  in Phalcon  `from the box`. 

##### In this release I have change the sctructure for releases result viewing. 
For every next release it's testing results will be commited in repository (`bm/result-releases/0.0.5/output`, `bm/result-releases/0.0.6/output`, `bm/result-releases/...../output`, etc.)
And they can be viewed on [http://php-frameworks.semasping.info/bm/result-releases/0.0.6/index.php](http://php-frameworks.semasping.info/bm/result-releases/0.0.6/index.php) where `0.0.6` - release version.
That links will be added to release informations on github

#### This release: [https://github.com/semasping/php_frameworks_for_tests/releases/tag/0.0.6](https://github.com/semasping/php_frameworks_for_tests/releases/tag/0.0.6)
#### Commits in this release:
* [results for 0.0.5](https://github.com/semasping/php_frameworks_for_tests/commit/9d8474134a163869ddcbf71532b0e28360a702cb)
* [new structure for releases result viewing](https://github.com/semasping/php_frameworks_for_tests/commit/fa9801a67a19b2985f7cd9f1e200f4901a312a12)
* [add cache tests for phalcon (for release 0.0.6)](https://github.com/semasping/php_frameworks_for_tests/commit/5e2e48b53e5b3112fe4e34910e989258adb1f9b5)
* [result of testing release 0.0.6](https://github.com/semasping/php_frameworks_for_tests/commit/1e064a61a8e31e229f85f643b952e44ab6969145)


## Roadmap:
* ~~Try to use Cache for all frameworks~~ (Done for laravel. Done for Phalcon)
* Find Eager Loading functional for Phalcon 3.2 (or try `stibiumz/phalcon.eager-loading`  for Phalcon 1.3.* - 2.0.*.)
* Implementing a test application and running tests on Symfony
* Implementing a test application and running tests on Yii
* Connection with https://blackfire.io/
* Deal with the Docker and wrap it all up in it. To be able to quickly deploy to a more powerful server for comparison.

#### PS: More information about structure of test application
* Part 1. [Introduction](https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-1). - Why i decide to do new bencmark of php frameworks.
* Part 2. [Database scheme and generating data for testing app](https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-2-database-scheme-and-generating-data-for-testing-app). - Description of application, database structure and data.
* Part 3. [Phalcon](https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-3-phalcon)
* Part 4. [Laravel](https://steemit.com/programming/@semasping/benchmark-php-frameworks-part-5-laravel)
* Part 5. [Cache and Eager Loading for Laravel framework](https://steemit.com/utopian-io/@semasping/cache-and-eager-loading-for-laravel-framework-benchmark-of-php-frameworks-v0-0-5)


<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@semasping/add-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsemasping
permlinkadd-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":95885735,"name":"php_frameworks_for_tests","full_name":"semasping/php_frameworks_for_tests","html_url":"https://github.com/semasping/php_frameworks_for_tests","fork":false,"owner":{"login":"semasping"}},"pullRequests":[],"platform":"github","type":"development","tags":["utopian-io","programming","phpframework","phalcon","laravel"],"users":["semasping"],"links":["https://github.com/semasping/php_frameworks_for_tests/releases/tag/0.0.6","https://steemitimages.com/DQme6B99o1s4f8LpKMfXnHWSc3AcroAShYSgT5PdAtgfNHm/006screenshot-php-frameworks.semasping.info%202018-01-29%2020-43-59-307.png","http://php-frameworks.semasping.info/bm/result-releases/0.0.6/index.php","https://github.com/semasping/php_frameworks_for_tests/commit/9d8474134a163869ddcbf71532b0e28360a702cb","https://github.com/semasping/php_frameworks_for_tests/commit/fa9801a67a19b2985f7cd9f1e200f4901a312a12","https://github.com/semasping/php_frameworks_for_tests/commit/5e2e48b53e5b3112fe4e34910e989258adb1f9b5","https://github.com/semasping/php_frameworks_for_tests/commit/1e064a61a8e31e229f85f643b952e44ab6969145","https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-1","https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-2-database-scheme-and-generating-data-for-testing-app","https://steemit.com/programming/@semasping/benchmarking-php-frameworks-part-3-phalcon","https://steemit.com/programming/@semasping/benchmark-php-frameworks-part-5-laravel","https://steemit.com/utopian-io/@semasping/cache-and-eager-loading-for-laravel-framework-benchmark-of-php-frameworks-v0-0-5"],"image":["https://steemitimages.com/DQme6B99o1s4f8LpKMfXnHWSc3AcroAShYSgT5PdAtgfNHm/006screenshot-php-frameworks.semasping.info%202018-01-29%2020-43-59-307.png"],"moderator":{"account":"helo","time":"2018-01-30T00:39:22.498Z","reviewed":true,"pending":false,"flagged":false}}
created2018-01-29 20:14:33
last_update2018-01-30 00:39:21
depth0
children4
last_payout2018-02-05 20:14:33
cashout_time1969-12-31 23:59:59
total_payout_value59.521 HBD
curator_payout_value26.200 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,413
author_reputation8,942,708,173,193
root_title"Add cache for Phalcon [Benchmark of php frameworks v0.0.6]"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id33,368,118
net_rshares14,304,297,058,847
author_curate_reward""
vote details (51)
@erikaflynn ·
Ни фига не поняла, но я За! За качественные вклады в мир open-source:-)
properties (22)
authorerikaflynn
permlinkre-semasping-add-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6-20180130t184350782z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-30 18:43:51
last_update2018-01-30 18:43:51
depth1
children0
last_payout2018-02-06 18:43:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length71
author_reputation12,282,595,621,854
root_title"Add cache for Phalcon [Benchmark of php frameworks v0.0.6]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id33,636,097
net_rshares0
@helo ·
Thank you for the contribution. It has been approved.

Very detailed

Please add a license to your repo.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authorhelo
permlinkre-semasping-add-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6-20180130t004016977z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-30 00:40:18
last_update2018-01-30 00:40:18
depth1
children1
last_payout2018-02-06 00:40:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length223
author_reputation121,547,934,535,311
root_title"Add cache for Phalcon [Benchmark of php frameworks v0.0.6]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id33,418,853
net_rshares0
@semasping ·
Thank you!

>Please add a license to your repo

Done
properties (22)
authorsemasping
permlinkre-helo-re-semasping-add-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6-20180130t023216907z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-30 02:32:15
last_update2018-01-30 02:32:15
depth2
children0
last_payout2018-02-06 02:32:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length52
author_reputation8,942,708,173,193
root_title"Add cache for Phalcon [Benchmark of php frameworks v0.0.6]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id33,441,636
net_rshares0
@utopian-io ·
### Hey @semasping I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-semasping-add-cache-for-phalcon-benchmark-of-php-frameworks-v0-0-6-20180131t031327470z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-31 03:13:27
last_update2018-01-31 03:13:27
depth1
children0
last_payout2018-02-07 03:13:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,085
author_reputation152,955,367,999,756
root_title"Add cache for Phalcon [Benchmark of php frameworks v0.0.6]"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id33,737,724
net_rshares0