Skip to content Skip to sidebar Skip to footer

Very Slow Ajax Response On Yii Framework

i am having strange issue with yii framework. on localhost, ajax response takes 200ms (which is fast and i am satsified) where as on my live server, same function take 4 to 7 secon

Solution 1:

I would try a few things. First off after you echo your json I would kill your script to make sure nothing else runs:

if ($rows) {
    echo json_encode($rows);
    die();
}

Also on your index.php make sure you have the site taken out of debug mode, if you have either of the middle two lines that start with defined() enabled each page load Yii is recreating cached files and it can take a while, especially if you have extensions like bootstrap included. I have had this exact issue when doing some work for someone and their site was hosted on GoDaddy. For some reason the file creation was really slow and was really dragging everything.

<?php$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/test.php';

//defined('YII_DEBUG') or define('YII_DEBUG',true);//defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);require_once($yii);
Yii::createWebApplication($config)->run();

Also are any other functions running slow? Any errors in your error log?

Another option to help debug create another action that doesn't require a AJAX call. It is much easier to debug this way instead of relying on ajax, plus it helps you narrow down the source of the problem. Plus don't know why but you get your array of rows then re-populate your array of rows, this is very redundant.

publicfunctionactionCheckpopup() {
    $user_id = $_GET['uid'];

    $rows = Yii::app()->db->createCommand()
            ->select('*')
            ->from('saved_designs')
            ->where('uid=:id', array(':id' => $user_id))
            ->order('date desc')
            ->queryAll();

    echo json_encode($rows);
    die();
}

Then simply use a browser and go to http://yoursite.com/index.php/request/checkpopup?uid=1

Post a Comment for "Very Slow Ajax Response On Yii Framework"