我在 cakephp3 上的脚本太长而无法加载
Posted
技术标签:
【中文标题】我在 cakephp3 上的脚本太长而无法加载【英文标题】:my script on cakephp3 is too long to load 【发布时间】:2016-01-29 11:31:15 【问题描述】:我正在尝试制作自己的函数,但我不明白为什么加载需要太多时间。
如果有人可以帮忙?
我想注意到列表、编辑或添加客户等其他功能运行良好。
这是我的代码:
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Collection\Collection;
/**
* Customer Controller
*
* @property \App\Model\Table\CustomerTable $Customer
*/
class CustomerController extends AppController
/**
* Index method
*
* @return void
*/
/**
*Login method
*
*@param string|null $login Customer login
*@param string|null $pasword Customer password
*@return true Redirects to \connection index
*/
public function login()
//$this->layout = 'default2';
// Si vous accédez à la session plusieurs fois,
// vous voudrez probablement une variable locale.
$session = $this->request->session();
if ($this->request->is('post'))
$query = $this->Customer->find('all', [
/*'CustLogin' => $this->request->data['login'],
'CustPassword' => $this->request->data['password'],*/
'conditions' => [
'Customer.CustLogin ' => $this->request->data['login'],
'Customer.CustPassword ' => $this->request->data['password']
]
]);
$row = $query->first();
//debug($row);
if(count($row) == 1)
$customer = $row->toArray();
$this->set('customer', $customer);
$session->write('customer_session', $customer);
//$this->redirect(array('action' => 'index'));
$this->setAction('dashboard');
else
$this->Flash->error('Votre username ou mot de passe est incorrect.');
/**
*logout method to disconnect customer
*
*/
public function logout()
$this->request->session()->destroy();
$this->redirect('/customer/login');
public function dashboard()
$session = $this->request->session();
if(isset($session) && !empty($session))
$customer = $session->read('customer_session');
if( isset($customer) && !empty($customer) )
$this->set('customer', $customer);
//$this->set('_serialize', ['customer']);
//************on doit recuperer son credit
$this->loadModel('Credits');
$query = $this->Credits->find('all', [
'conditions' => [
'Credits.AccID ' => $customer['CustIdCredit']
]
]);
$row = $query->first();
$this->set('credit', $row->toArray());
//******************on recherche les sms inbound du jour
$yesterday = strtotime('yesterday midnight');
$today = strtotime('today midnight'); //on recupère le jour
$tomorrow = strtotime('tomorrow midnight');
$aujourdhui = str_replace(' ', '@', date('Y.m.d H:i:s', $today)); //. ' - Today for example purposes<br />';
$demain = str_replace(' ', '@', date('Y.m.d H:i:s', $tomorrow));
$hier = str_replace(' ', '@', date('Y.m.d H:i:s', $yesterday));
//echo '/**********aujourdhui start $aujourdhui on and end on $demain ****/';
//var_dump($aujourdhui);//******** date d aujourd'hui
//var_dump($demain);//********* date de demain
//echo '/**********this week start on $ceweekd and end on $ceweeke ****/';
$this_week_start = strtotime("this week midnight");
$next_week_start = strtotime("next week midnight");
$ceweekd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start));
$ceweeke = str_replace(' ', '@', date('Y.m.d H:i:s', $next_week_start));//******this week end on next week start
//var_dump($ceweekd);
//var_dump($ceweeke);
//echo '/**********last week start on $ceweekld and end on $ceweekle ****/';
$last_week_start = strtotime("last week midnight");
//$last_week_end = strtotime("last week, +6 days");
$ceweekld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_week_start));
$ceweekle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start));
//var_dump($ceweekld);
//var_dump($ceweekle);
//echo '/**********this month start on $cemonthd and end on $cemonthe ****/';
$this_month_start = strtotime("first day of this month midnight");
$next_month_start = strtotime("first day of next month midnight");
$cemonthd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start));
$cemonthe = str_replace(' ', '@', date('Y.m.d H:i:s', $next_month_start));//******this month end on next month start
//var_dump($cemonthd);
//var_dump($cemonthe);
//echo '/**********last month start on $cemonthld and end on $cemonthle ****/';
$last_month_start = strtotime("first day of last month midnight");
//$last_week_end = strtotime("last week, +6 days");
$cemonthld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_month_start));
$cemonthle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start));
//var_dump($cemonthld);
//var_dump($cemonthle);
//*****************on selectionne toutes les conncetions utilisateur
$this->loadModel('Connection');
$query = $this->Connection->find('all', [
'conditions' => [
'Connection.CustId ' => $customer['CustId']
]
]);
$row = $query->all();
//$this->set('connection', $row->toArray()); //var_dump(count($row->toArray()));
//***********on boucle dessus pour avoir les inbound par msgAccountID and msgBody
$this->loadModel('Outbox');
$credit_today = 0;$credit_week = 0;$credit_lweek = 0;$credit_month = 0; $credit_lmonth = 0;
if(count($row->toArray()) == 1)
$array1 = $row->toArray();
$connection = $array1[0]->toArray();
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $aujourdhui,'Outbox.MsgReceivedTime <' => $demain]);
$count_jour = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_jour = (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $ceweekd,'Outbox.MsgReceivedTime <' => $ceweeke]);
$count_week = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_week = (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $ceweekld,'Outbox.MsgReceivedTime <' => $ceweekle]);
$count_lweek = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lweek = (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthld,'Outbox.MsgReceivedTime <' => $cemonthle]);
$count_lmonth = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lmonth = (int)$sum[0]->sum;
$this->set('inbound_jour', $count_jour);
$this->set('cr_inboud_jour', $credit_jour);
$this->set('inbound_week', $count_week);
$this->set('credit_inbound_week', $credit_week);
$this->set('inbound_lweek', $count_lweek);
$this->set('credit_inbound_lweek', $credit_lweek);
$this->set('inbound_month', $count_month);
$this->set('credit_inbound_month', $credit_month);
$this->set('inbound_lmonth', $count_lmonth);
$this->set('credit_inbound_lmonth', $credit_lmonth);
else //************** le client a plusieurs connections
$count_jour = 0;$credit_jour = 0;$count_week = 0;$credit_week = 0;$count_lweek = 0;$credit_lweek = 0;
$count_month = 0;$credit_month = 0; $count_lmonth = 0;$credit_lmonth = 0;
foreach($row->toArray() as $value)
$connection = $value->toArray();
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $aujourdhui,'Outbox.MsgReceivedTime <' => $demain]);
$count_jour += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_jour += (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $ceweekd,'Outbox.MsgReceivedTime <' => $ceweeke]);
$count_week += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_week += (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $ceweekld,'Outbox.MsgReceivedTime <' => $ceweekle]);
$count_lweek += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lweek += (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$count_month += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month += (int)$sum[0]->sum;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthld,'Outbox.MsgReceivedTime <' => $cemonthle]);
$count_lmonth += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lmonth += (int)$sum[0]->sum;
$this->set('inbound_jour', $count_jour);
$this->set('cr_inboud_jour', $credit_jour);
$this->set('inbound_week', $count_week);
$this->set('credit_inbound_week', $credit_week);
$this->set('inbound_lweek', $count_lweek);
$this->set('credit_inbound_lweek', $credit_lweek);
$this->set('inbound_month', $count_month);
$this->set('credit_inbound_month', $credit_month);
$this->set('inbound_lmonth', $count_lmonth);
$this->set('credit_inbound_lmonth', $credit_lmonth);
//****************************
//***********on boucle dessus pour avoir les outbound par msgAccountID and msgBody
$this->loadModel('Inbox');
if(count($row->toArray()) == 1)
$array1 = $row->toArray();
$connection = $array1[0]->toArray();
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $aujourdhui,'Inbox.MsgReceivedTime <' => $demain]);
$count_jour = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_jour = (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $ceweekd,'Inbox.MsgReceivedTime <' => $ceweeke]);
$count_week = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_week = (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $ceweekld,'Inbox.MsgReceivedTime <' => $ceweekle]);
$count_lweek = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lweek = (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]);
$count_lmonth = $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lmonth = (int)$sum[0]->sum;
$this->set('outbound_jour', $count_jour);
$this->set('cr_outboud_jour', $credit_jour);
$this->set('outbound_week', $count_week);
$this->set('credit_outbound_week', $credit_week);
$this->set('outbound_lweek', $count_lweek);
$this->set('credit_outbound_lweek', $credit_lweek);
$this->set('outbound_month', $count_month);
$this->set('credit_outbound_month', $credit_month);
$this->set('outbound_lmonth', $count_lmonth);
$this->set('credit_outbound_lmonth', $credit_lmonth);
else
//var_dump($row->toArray());
$count_jour = 0;$count_week = 0;$count_weekl = 0;$count_month = 0;$count_lmonth = 0;
$credit_jour = 0;$credit_week = 0;$credit_weekl = 0;$credit_month = 0;$credit_lmonth = 0;
foreach($row->toArray() as $value)
$connection = $value->toArray();
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $aujourdhui,'Inbox.MsgReceivedTime <' => $demain]);
$count_jour += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_jour += (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $ceweekd,'Inbox.MsgReceivedTime <' => $ceweeke]);
$count_week += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_week += (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $ceweekld,'Inbox.MsgReceivedTime <' => $ceweekle]);
$count_lweek += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lweek += (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$count_month += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month += (int)$sum[0]->sum;
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]);
$count_lmonth += $query->count('*');
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_lmonth += (int)$sum[0]->sum;
$this->set('outbound_jour', $count_jour);
$this->set('cr_outboud_jour', $credit_jour);
$this->set('outbound_week', $count_week);
$this->set('credit_outbound_week', $credit_week);
$this->set('outbound_lweek', $count_lweek);
$this->set('credit_outbound_lweek', $credit_lweek);
$this->set('outbound_month', $count_month);
$this->set('credit_outbound_month', $credit_month);
$this->set('outbound_lmonth', $count_lmonth);
$this->set('credit_outbound_lmonth', $credit_lmonth);
else
$this->Flash->error(__('Votre session a expiré, veuillez vous reconnecter!'));
$this->setAction('login');
else
$this->Flash->error(__('Votre session a expiré, veuillez vous reconnecter!'));
$this->setAction('login');
public function oprSmsTraffic()
$this->loadModel('Inbox');
$this->loadModel('Outbox');
$yesterday = strtotime('yesterday midnight');
$today = strtotime('today midnight'); //on recupère le jour
$tomorrow = strtotime('tomorrow midnight');
$aujourdhui = str_replace(' ', '@', date('Y.m.d H:i:s', $today)); //. ' - Today for example purposes<br />';
$demain = str_replace(' ', '@', date('Y.m.d H:i:s', $tomorrow));
$hier = str_replace(' ', '@', date('Y.m.d H:i:s', $yesterday));
$this_week_start = strtotime("this week midnight");
$next_week_start = strtotime("next week midnight");
$ceweekd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start));
$ceweeke = str_replace(' ', '@', date('Y.m.d H:i:s', $next_week_start));//******this week end on next week start
$last_week_start = strtotime("last week midnight");
$ceweekld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_week_start));
$ceweekle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start));
$this_month_start = strtotime("first day of this month midnight");
$next_month_start = strtotime("first day of next month midnight");
$cemonthd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start));
$cemonthe = str_replace(' ', '@', date('Y.m.d H:i:s', $next_month_start));//******this month end on next month start
$last_month_start = strtotime("first day of last month midnight");
$cemonthld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_month_start));
$cemonthle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start));//*********last month end on this month start
$this->set('customer', $this->paginate($this->Customer));
$this->set('_serialize', ['customer']);
if ($this->request->is('post'))
$data = $this->request->data;
if((int)$data['idCheckPHandler_Flt_4'] == 0 )
$this->set('operator', 0);
else
$this->loadModel('Connection');
$query = $this->Connection->find('all', [
'conditions' => [
'Connection.CustId ' => (int)$data['operator'],
]
]);
foreach($query as $value)
$operator = $value;
$operator = $operator->toArray();
$this->set('operator', $operator);
$query = $this->Inbox->find('first')->where(['Inbox.MsgAccountID ' => $operator['ConAccountid'], 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]);
$count_lmonth += $query->count('*');
debug($count_lmonth);
else
$this->set('operator', 0); $count_month = 0;$credit_month = 0;
//*******on recherche pour MTN
$query = $this->Inbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$this->set('count_Imonth',(int)$count_month);
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$this->set('credit_Imonth',(int)$credit_month);
$count_month = 0;
for($i = 0; $i < 10; $i++)
$query = $this->Inbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Inbox.MsgTo = 800'.$i]);
$count_month = $query->count('*');
$this->set('count_Imonth_800'.$i,(int)$count_month);
$count_month = 0;
//for($i = 0; $i < 10; $i++)
$query = $this->Inbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Inbox.MsgTo NOT BETWEEN 8000 AND 8009']);
$count_month = $query->count('*');
$this->set('count_Imonth_autres',(int)$count_month);
//
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$this->set('count_Omonth',(int)$count_month);
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$this->set('credit_Omonth',(int)$credit_month);
$count_month = 0;
for($i = 0; $i < 10; $i++)
$query = $this->Outbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Outbox.MsgTo = 800'.$i]);
$count_month = $query->count('*');
$this->set('count_Omonth_800'.$i,(int)$count_month);
$count_month = 0;
//for($i = 0; $i < 10; $i++)
$query = $this->Outbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Outbox.MsgTo NOT BETWEEN 8000 AND 8009']);
$count_month = $query->count('*');
$this->set('count_Omonth_autres',(int)$count_month);
//
$count_month = 0;
//*******on recherche pour ORANGE
$query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$this->set('count_Imonth1',(int)$count_month);
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$this->set('credit_Imonth1',(int)$credit_month);
$count_month = 0;
for($i = 0; $i < 10; $i++)
$query = $this->Inbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Inbox.MsgTo = 800'.$i]);
$count_month = $query->count('*');
$this->set('count_Imonth1_800'.$i,(int)$count_month);
$count_month = 0;
//for($i = 0; $i < 10; $i++)
$query = $this->Inbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]);
$query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Inbox.MsgTo NOT BETWEEN 8000 AND 8009']);
$count_month = $query->count('*');
$this->set('count_Imonth1_autres',(int)$count_month);
//
$count_month = 0;
$query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$count_month = $query->count('*');
$this->set('count_Omonth1',(int)$count_month);
$sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray();
$credit_month = (int)$sum[0]->sum;
$this->set('credit_Omonth1',(int)$credit_month);
$count_month = 0;
for($i = 0; $i < 10; $i++)
$query = $this->Outbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Outbox.MsgTo = 800'.$i]);
$count_month = $query->count('*');
$this->set('count_Omonth1_800'.$i,(int)$count_month);
$count_month = 0;
//for($i = 0; $i < 10; $i++)
$query = $this->Outbox->find(
'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],]
)->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]);
$query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]);
$query->where(['Outbox.MsgTo NOT BETWEEN 8000 AND 8009']);
$count_month = $query->count('*');
$this->set('count_Omonth1_autres',(int)$count_month);
//
我的截图:
【问题讨论】:
对我来说,我不知道任何形式的cakephp
,看起来您正在dashboard
方法中执行数百个查询
【参考方案1】:
正如@RamRaider 已经说过的,这很可能是由于您尝试执行的查询数量庞大。您可以通过查看 CakePHPs Debug Tool 的 SQL 选项卡来验证这一点。
您会看到相当多的查询。您还可以查看哪些查询需要很长时间才能执行。
其他可能的解决方案是:
减少在控制器中执行的查询量。 使用CakePHP's result caching 将Aggregated data 存储在另一个数据库或表中最后一个需要另一个脚本来实际执行所有计算并选择您现在在页面请求中执行的操作。
This post 提供有关数据仓库的更多信息。
【讨论】:
以上是关于我在 cakephp3 上的脚本太长而无法加载的主要内容,如果未能解决你的问题,请参考以下文章