Javascript PHP-如何优化此脚本以使其执行更快?已经需要20秒来加载了

Javascript PHP-如何优化此脚本以使其执行更快?已经需要20秒来加载了,javascript,php,ajax,zend-framework,Javascript,Php,Ajax,Zend Framework,这是一个非常简单的脚本,它为一些使用Ajax/Javascript/jQuery的附属网站提供了一个按钮,这些附属网站通过下面的代码从我的服务器获取所需的插件。但是它花费了网站的大部分时间+/20秒,其他插件在30秒内加载 我不明白是什么原因导致装载如此缓慢?我做错了什么?你如何改进它 <?php header('Access-Control-Allow-Origin: *'); $customerid = $_GET['id']; $what = $_GET['button']; $

这是一个非常简单的脚本,它为一些使用Ajax/Javascript/jQuery的附属网站提供了一个按钮,这些附属网站通过下面的代码从我的服务器获取所需的插件。但是它花费了网站的大部分时间+/20秒,其他插件在30秒内加载

我不明白是什么原因导致装载如此缓慢?我做错了什么?你如何改进它

<?php
header('Access-Control-Allow-Origin: *');  
$customerid = $_GET['id'];
$what = $_GET['button'];
$id = substr('3' . rand(0,9999), 0-$length);

switch ($customerid) {
  case 'customer1':    
    break;
  case 'customer2':
    break;  
  default:
    $da = "https://server0/1.php?r={$id}&endof=end";
    $db = "https://server1?r={$id}";    
    $imagelink = "http://server2.com:8080/images/button.png";

    $a = "<a href={$da} id={$} class={$customerid}abutton onclick=\"typeof(_gaq)=='undefined'?'':_gaq.push(['_trackEvent', 'Mycompany', 'ButtonClick']);typeof(_gat)=='undefined'?'':_gat._getTrackerByName()._setAllowLinker(true); window.open(typeof(_gat)=='undefined'?this.href+'?referrer='+escape(window.location.href):_gat._getTrackerByName()._getLinkerUrl(this.href+'?referrer='+escape(window.location.href)), '_blank', 'width=480,height=360,resizable=no,toolbar=no,menubar=no,location=no,status=no'); return false\"><img src=\"{$imagelink}\" /></a>";

    $b = "<a href={$db} id={$} class={$customerid}aabutton onclick=\"typeof(_gaq)=='undefined'?'':_gaq.push(['_trackEvent', 'Mycompany', 'ButtonClick']);typeof(_gat)=='undefined'?'':_gat._getTrackerByName()._setAllowLinker(true); window.open(typeof(_gat)=='undefined'?this.href+'?referrer='+escape(window.location.href):_gat._getTrackerByName()._getLinkerUrl(this.href+'?referrer='+escape(window.location.href)), '_blank', 'width=480,height=360,resizable=no,toolbar=no,menubar=no,location=no,status=no'); return false\"><img src=\"{$imagelink}\" /></a>";

    $section = file_get_contents("http://server2/ajax/getstatus");
    $section = json_decode($section);
    if ($section->result){
      switch($what) {
        case 'v':
          echo $b;
          break;
        case 'a':
          echo $a;
          break;
        case 'b':
          echo $a . $b;
          break;
      }

    } else {
      switch($what) {
        case 'v':
          break;
        case 'a':
          echo $a;
          break;
        case 'b':
          echo $a;
          break;
      }
    }   
    break;
}

?>

您是否检查了请求
http://server2/ajax/getstatus
直接查看这是否是瓶颈?什么是
http://server2/ajax/getstatus
它会返回多少数据?请参见我上面的编辑。Zend framework用于获取状态,它占用了几乎+/ 秒的时间@dorianm:检查您的进一步诊断可能是会话中的问题。如果有多个页面使用同一个会话,它们必须等待另一个页面完成。您可以关闭对会话的写入,以测试这是否是问题所在,并提高性能。我以前在zend遇到过这个问题。
  public function getstatusAction() {
    $this->_response->setHeader('Access-Control-Allow-Origin', '*');       
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender();   
    $post = $this->getRequest()->getQuery();
    $data = (object) $post;
    $this->db = Application_Model_Db::db_load();

    $sql = "select *from sh_av_users where
              status='online'
        limit 1";
    $result = $this->db->fetchAll($sql);
    if (count($result) > 0) {
      $json = array(
          'result' =>true,
      );      
    }   else {
      $json = array(
          'result' =>false,
      );        
    } 

    $content = Zend_Json::encode($json);
    $this->getResponse()
            ->setHeader('Content-Type', 'application/json')
            ->setBody($content)
            ->sendResponse();

    exit;
  }