Yii2 app slow loading time

Hi guys,

I’ve developed a Yii2 app based on the advanced application template. I’ve uploaded it to my hosting server and found that the loading time is very slow. Below is some screenshot from Chrome Dev tools when I execute the ‘create’ action.

The TTFB is about 20s which is very bad. The hosting server is located in the same country as I am and running on PHP 5.6.

Any tips on what and where I should troubleshoot to improve the loading time?

Looks really bad. Even on cheapest shared hosting it’s usually much better.

  1. See if APC/OpCache is enabled.

  2. It it slow locally?

Hi samdark. I believe APC is a deprecated extension and has been replaced with OpCache. Instead, OpCache is enabled together with APCu. Connectivity should be fine as well.

I’ve turned on debug on my local development machine to profile the app. The resource requirement of the app looks really nominal.

Right now, I’m trying to see if we can turn on debug on the live app to get some data and also trying out the app on other cloud providers.

Anything else you would suggest? Does the asset bundle and number of queries executed looks heavy to you?


What does the TTFB look like if you try a simple script that does nothing but echo phpinfo? Just to see what the performance is like without Yii involved.

HI nat3863,

maybe this can help you http://www.yiiframework.com/doc-2.0/guide-tutorial-performance-tuning.html#enable-schema-caching

Thanks guys. I’ve created a phpinfo file to test out the loading time. It is loading similarly slow as well. Pingdom and Google PageSpeed Insight also shows that the load time is in the excess of 20s when loading the info.php page.

I then signed up for a trial with another cloud hosting, quickly spun up an instance and loaded my app. The same item/create action took an average 300ms to load even when the server was located in Germany.

Time to review my hosting provider. Thanks again guys.

Was anything else found on this? I have my site where sometimes the same page will take up to 30 seconds to load and other times it will take less than 2 seconds with the same information on it. It does the same thing on my local development XAMPP server as well. I did the change of the host from localhost to as well. When I check the profiling the majority of the time is spent in the



[color=#333333]yii\db\Connection::open [/color]

[color=#333333]Opening DB connection: mysql:host=;dbname=testdb_development[/color]

[font="Helvetica Neue, Helvetica, Arial, sans-serif"][color="#333333"][size=4]


I’m not sure why this would vary this much for the same page.

As a follow-up, I ended up switching hosting companies and the problem went away.