CakePHP 1.3: High CPU Usage

2019-04-17 12:12发布

问题:

I have a CakePHP application that is running on a shared hosting account, which the provider has been bugging me a lot (A2HOSTING) that my account is excessively using CPU resources, sometimes 100%.

Just on the last few hours alone, CPanel is reporting high CPU Usage. I have spoken with them and they said that everything is pointing to the 'webroot' directory. There I only have index.php and css.php.

Any ideas, what can be causing this issue, and what can I do to fix it, as they are threatening to suspend my account.

Thanks,

回答1:

There is not a whole lot to say without a more information. For now, Let's start with what is using 100% cpu? MySQL or PHP? Also, the conditions you use. Any associations and so on...

If it all works ok on your local setup then I would start by looking at any differences between that and your server. Versions of CakePHP, PHP, MySQL... are they different? Is the server running some infamous version of one of them?

Let's blame the database: Is the database structure and data really identical, really? Look carefully as every detail. Do you have the same content in them? Exactly? Clone your dev database including all table definitions and data.

Sometimes I notice a lapse of logic on my part where a "clean" database will cause problems because I have had data in it during the whole development and for some reason I have missed that something (seemingly unrelated) will fail if a table is empty.

Let's blame PHP: When PHP ends up at 100% cpu, the problem is usually that it is stuck in a loop somewhere. Do you have one near that line? If you let the request run, do you just get a timeout or an out of memory?

Finding "first" should never result in out of memory unless your server has 200'000 related records being loaded. Try specifying recursive -1. That is: load absolutely nothing from any other table.

Reference: https://groups.google.com/forum/?fromgroups#!topic/cake-php/lS91s355_Pw

This post might help you to decrease the CPU overload.