Hi all,
I got some issues with ajax requests performance. I wrote a script in a page which does a ajax request to a controller, this controller then generates a json answer which takes, wait for it, 2000ms.
I wrote the same request with a piece of code cutted by me esternally to Yii and it took 100ms.
Now, how can i solve the issue?
I even thought to write a lil script myself inside the app which manage Json requests, but i dont know how and where to check if the user logged in.
Any idea?
Tnx everybody.
konapaz
(Konapaz)
April 10, 2013, 5:35pm
2
Ηι dragonWeb
Are you sure that your Ajax code do the same thing that Ajax Yii does?
could you post the code both of two cases ?
public function actionBankAccountJson(){
if (Yii::app()->request->isAjaxRequest)
{
header('Content-type: application/json');
$sql = 'SELECT bank_account.id as id, bank_account.name as name, bank.name as bank FROM bank_account
INNER JOIN bank ON bank.id = bank_id';
$cc=Yii::app()->db->createCommand($sql)->queryAll();
$result = array();
$result['tot'] = 0;
foreach( $cc as $conto ){
$saldoAttuale = BankAccount::getSaldoAl($conto['id']);
$result['items'][] = array(
'id' => $conto['id'],
'name' => $conto['name'],
'bank' => $conto['bank'],
'saldo' => $saldoAttuale,
);
$result['tot'] += $saldoAttuale;
}
echo json_encode($result);
Yii::app()->end();
}
}
My code do the same thing, but I use php function in other page
konapaz
(Konapaz)
April 11, 2013, 11:56am
4
dragonWeb:
public function actionBankAccountJson(){
if (Yii::app()->request->isAjaxRequest)
{
header('Content-type: application/json');
$sql = 'SELECT bank_account.id as id, bank_account.name as name, bank.name as bank FROM bank_account
INNER JOIN bank ON bank.id = bank_id';
$cc=Yii::app()->db->createCommand($sql)->queryAll();
$result = array();
$result['tot'] = 0;
foreach( $cc as $conto ){
$saldoAttuale = BankAccount::getSaldoAl($conto['id']);
$result['items'][] = array(
'id' => $conto['id'],
'name' => $conto['name'],
'bank' => $conto['bank'],
'saldo' => $saldoAttuale,
);
$result['tot'] += $saldoAttuale;
}
echo json_encode($result);
Yii::app()->end();
}
}
My code do the same thing, but I use php function in other page
Could you give your php native code too?
I think the problem is the $saldoAttuale = BankAccount::getSaldoAl($conto[‘id’]);
post also the getSaldoAl method code