I'm developing an online sales management application for a bakery. I decided to use Cake PHP as a framework and Mochahost as hosting provider since I haven't heard any major drawbacks of both.
My application is currently under the development phase. The MySQL user it uses has only a single database available to it, the database has only 10-15 tables and currently maximum 50 rows in total (most tables empty yet).
I'm not sure, since debug kit shows only a single (or if session timeout 3) queries taking acceptable time (less that 0.2 of a second) but timers say Controller.shutdown event or Controller.startup event takes anywhere from 30 000 milisecs to 58 000 miliseconds (!!).
Each and every load of my page takes anywhere from 30 to 60 seconds(!!!). Found out that it is caused by getting schema information (getSchemaCollection(), typeMap()). Okay, I know, development settings makes cache only available for 2 mins or so, but every time I reload the page it takes 30-60 seconds with no table associations defined at all. No, I am not running anything unusually complex, I use Auth component and database Sessions...
With defined (deep) associations it runs for so long that page dies HTTP 504 Gateway Time-out or 502 Bad Gateway. With no response at all and according to cpanel the script is still runnning in background blocking one of my available entry processes and mysql user sign-ins. This means I can't even develop my page since I can't load it even once to have caches further on. Developing on a private development server couldn't also work: at the first production load, it would also try to build the cache.
Also disabling cache by calling Cache::disable() didn't help at all.
I also noticed that there is one query that takes 30-60 seconds to run on the mysql server included in the hosting plan, and that is SHOW SCHEMAS. I guess cakephp uses this query when getSchemaCollection() gets called for the first time.
How long this query runs for you? Am I wrong that this is totally inacceptable and I should ask for a refound or an immediate fix? I cant afford pageloadings this long since the bakery has 500 costumers daily, so every purchase would use heavy sql, etc.
Current sessions table:
Field Type Null Key Default Extra
id char(40) NO PRI NULL
created timestamp NO CURRENT_TIMESTAMP
updated timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
data blob YES NULL
expries int(10) YES NULL
ipAdress varchar(15) NO NULL
user_id char(36) YES MUL NULL
This table has user_id as foreign key to users table's PK (id).
SessionsTable.php:
class SessionsTable extends Table
{
public static $uid = null;
public function initialize(array $config)
{
parent::initialize($config);
//$this->belongsTo('Users');
}
public function implementedEvents()
{
return array(
'Model.beforeSave' => 'beforeSave',
);
}
public function beforeSave(Event $event, EntityInterface $entity, $options = []) {
$request = Router::getRequest();
$request->trustProxy = true;
$entity->set('ipAdress', $request->clientIp());
if (!is_null(self::$uid)) $entity->set('user_id', self::$uid);
}
}
Update I am not an expert at php profiling but if im correct the correspondig significant value is PDOStatement->execute() which gets called 5 times for 94.13 self(?)/incl.(?)
Update 2 I have recieved a quick and satisfying reply from mochahost saying show schemas query is disabled for various understandable performance reasons. They advised me to use SHOW SCHEMAS LIKE 'myuser_%' since all database names are in 'user_dbname' format. So my question is where and how should i impement this to be used by default in cakephp?
'debug' => false,; b) make sure that your app has the necessary permissions to write it's localtmpdirectory (to cache ORM metadata); c)composer install --no-dev- code-kobold