Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is CakePHP 3 so slow at autoloading classes on a Vagrant box?

Setup

  • Vagrant box (2gb memory)
  • Apache/2.2.22 (Ubuntu)
  • PHP 5.4.38-1+deb.sury.org~precise+2 (cli) (built: Feb 20 2015 12:16:47)
  • CakePHP 3

I just installed a fresh CakePHP 3 with composer, and with the very basic default home page i noticed the page took like 4s ~ 5s to load. Here are the benchmarks (kitchen.com is the server alias):

Chrome Dev Tools

enter image description here

PhpStorm + Xdebug

enter image description here


Even composer.phar dumpautoload -o didn't change a thing.


Sometimes some REST calls (returning small json) could reach ~12s because of the autoload and that php_sapl_name:

Ajax REST call

  • Request URL: http://kitchen.com/admin/kitchen/settings.json
  • Request Method: GET
  • Response:
{
    "settings": {
        "sitename": "Site settings",
        "desciption": "Lorem ipsum"
    }
}
  • Controller action:
public function index() {
    $this->set('settings', ['sitename' => 'Site settings', 'desciption' => 'Lorem ipsum']);
    $this->set('_serialize', ['settings']);
}

Chrome dev tools and PhpStorm + Xdebug

enter image description here

enter image description here


So is it a common bug on CakePHP 3 or it can come from my server configuration ?

like image 388
hjrshng Avatar asked Sep 28 '22 08:09

hjrshng


1 Answers

You should make sure that you have opcode caching enable. In general PHP performance suffers greatly without opcode caching.

Also ensure your machine is not constrained in terms of IO performance. Because PHP applications need to load a number of files on every request, disk IO matters.

I would say you results are very far from typical. I typically get responses from baked code in <150ms on my 2 year old laptop from CakePHP.

Edit: I re-read your question and noticed that you are using VM. Shared VM filesystems are notoriously slow. If you are sharing from the host into the guest OS, see if you get better performance by moving your code off of the shared filesystem.

like image 101
Mark Story Avatar answered Oct 02 '22 13:10

Mark Story