Yii Framework Forum: Json And Ajax Very Slow - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Json And Ajax Very Slow Rate Topic: -----

#1 User is offline   dragonWeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 16-February 13

Posted 10 April 2013 - 11:46 AM

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.
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

Posted 10 April 2013 - 12:35 PM

Ηι 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 ?
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   dragonWeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 16-February 13

Posted 11 April 2013 - 02:30 AM

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
0

#4 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

Posted 11 April 2013 - 06:56 AM

View PostdragonWeb, on 11 April 2013 - 02:30 AM, said:

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
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users