我不知道如何解决这个问题。在我的应用程序(Zend Framework、MySQL、jQuery)中,其中一个页面的加载时间超过了 10 秒。
它从数据库中加载不到 400 条记录,所以我认为瓶颈不在 MySQL 中。当然,相关表上的服务器端选择不是问题:
379 rows in set (0.00 sec)
Firebug 在原始请求中将延迟报告为等待服务器响应,“0 ---> 11.09s Waiting”。这是第一个请求,之后所有的 jQuery 代码都被加载,onLoad 时间为 11.54 秒。所以 jQuery 似乎也不是瓶颈。
没有其他控制器/操作需要这么长时间来响应,所以我无法想象这是一个 Apache 问题。剩下的就是采埃孚自己。
我想知道是否有办法测试延迟发生的位置。以下是相关行动的全文:
public function listAction()
{
$userDepts = new Application_Model_DbTable_UserDepartments;
$ptcpDepts = new Application_Model_DbTable_ParticipantDepts;
$participants = new Application_Model_DbTable_Participants;
$depts = new Application_Model_DbTable_Depts;
$ptcpAlerts = new Application_Model_DbTable_AlertsParticipants;
//check if sub-list is being passed
if ($this->_helper->flashMessenger->getMessages()) {
$passedList = $this->_helper->flashMessenger->getMessages();
$list = $passedList['0'];
} else {
$list = $participants->getStaffPtcps();
}
$goodList = array_unique($list);
$number = count($goodList);
$content = array();
foreach ($goodList as $id) {
$deptNames = array();
$ptcpInfo = $participants->getRecord($id);
$ptcpDept = $ptcpDepts->getList('depts', $id);
$flags = $ptcpAlerts->getPtcpAlerts($id);
if (count($flags) > 0) {
$flagTest = TRUE;
} else {
$flagTest = FALSE;
}
foreach ($ptcpDept as $did) {
$deptName = $depts->getDept($did);
$deptNames[$did] = $deptName['deptName'];
}
$content[$id] = $ptcpInfo;
$content[$id]['depts'] = $deptNames;
$content[$id]['flag'] = $flagTest;
}
foreach ($content as $c => $key) {
$sortLastName[] = $key['lastName'];
}
array_multisort($sortLastName, SORT_ASC, $content);
$this->view->list = $content;
$this->view->count = $number;
$this->view->layout()->customJS =
'<script type="text/javascript" src="/js/datePicker.js"></script>' .
'<script type="text/javascript" src="/js/ptcpCreate.js"></script>' .
'<script type="text/javascript" src="/js/editDataWithModal.js"></script>' .
'<script type="text/javascript" src="/js/filter.js"></script>';
$form = new Application_Form_AddParticipant;
$this->view->form = $form;
}
任何关于优化此代码的想法 - 或其他地方的指针 - 将不胜感激!