Php 如何减少此脚本的执行时间?

Php 如何减少此脚本的执行时间?,php,mysql,encryption,profiling,Php,Mysql,Encryption,Profiling,一个多星期以来,我一直在尝试优化MySQL查询脚本。最后,我决定在我的生产环境中安装Xdebug,我发现一些结果很有趣: 使用MySQL慢速查询,它不会返回服务器上更高的工作。所以这意味着我的查询一点也不慢。也许这是因为我还没有太多的数据 安装memcached减少了我的一些PHP执行时间,有时从5分钟减少到1或2分钟,但也出现了一些问题。Memcached不会为我的用户返回新条目。很明显,我是在数据库运行一分钟后从内存中获取数据的。所以不管怎样,我决定暂时不实现memcached。像这样的用户

一个多星期以来,我一直在尝试优化MySQL查询脚本。最后,我决定在我的生产环境中安装Xdebug,我发现一些结果很有趣:

  • 使用MySQL慢速查询,它不会返回服务器上更高的工作。所以这意味着我的查询一点也不慢。也许这是因为我还没有太多的数据
  • 安装memcached减少了我的一些PHP执行时间,有时从5分钟减少到1或2分钟,但也出现了一些问题。Memcached不会为我的用户返回新条目。很明显,我是在数据库运行一分钟后从内存中获取数据的。所以不管怎样,我决定暂时不实现memcached。像这样的用户并不多。无论如何,时间过得很慢
  • 这就是我的服务器应用程序的场景。但几天前,出于安全考虑,我实现了一个新模块,为我的应用程序上的所有对象创建了一个加密密钥。我为此实现了datacrypt类,它在我的笔记本电脑上的开发环境中运行得非常好

    我为什么来寻求帮助? 通过使用winCachegrind查看Xdebug评测,我发现datacrypt的实例化需要37218ms的执行时间,我的一些文件显示了10或15行,其中每一行动态生成加密密钥

    datacrypt类的大量使用是一个问题。它用于每个脚本文件中。因此,我需要获得一个新的fast类来生成一个加密的哈希,以便在我的应用程序中使用

    谁能给我推荐一个吗?或者我可以做些什么来使datacrypt运行得更快

    如果你想看看我的脚本,让我知道

        <div class="property-holder">
    <?php
    
        require BASE_DIR.'/controller/listing.php';
    
        if(is_array($rows)){
            echo $nav;  
        ?>
    <div id="properties-listing" class="content center container-wraps">
    <?php
            //$crypt =  new datacrypt();
            foreach($rows as $row){
    
                    //$pkey = $crypt->encrypt($row['property_type'].'-'.$row['property_id'].'-'.$row['broker_id'].'-'.$row['company_id']);
                        if($row[property_type] == 'development'){
                        $picture = (( $row['dev_logo']!='')?'<img class="ui-action" rel="open"  src="'.HOST.'thumbs/80x80/dev/'.$row['dev_logo'].'" />':'<img src="'.HOST.'imgss/noimage.jpg" width="80" height="80" />');
                        }else{
                        $picture = (( $row['image']!='')?'<img class="ui-action" rel="open"  src="'.HOST.'thumbs/80x80/'.$row['property_id'].'/'.$row['image'].'" width="80" height="80" />':'<img src="'.HOST.'imgss/noimage.jpg" width="80" height="80" />');
                        }
                        $prop.=' <div class="listing clearfix shadowbox" id="'.$pkey.'" ref="MLS-'.$row['property_id'].'"  >';
                        $prop.='<div class="listing-photo  left"><a href="#property-view" rel="load-content">'.$picture.'</a></div>';
                        $prop.='<div class="left listing-holder clearfix">';                    
                            $prop.='<h2 class="title"><span class="location"> '.$row['city'].', '.$row['estate'].', '.$row['country'].' </span> '.$row['property_name'].' <em class="company"> ( MLS-'.$row['property_id'].' )</em> '.($_SESSION[company_id]==$row[company_id]?'<span class="company ui-icon ui-icon-heart" ></span>':'').'</h2>';
                            $prop.='<div class="listing-description clearfix"><ul>';
    
                            $prop.='<div class="threebox left">';
                            $prop.='<li><span>'.T_('Tipo de propiedad').'</span><strong>'.$row['category'].' </strong></li>';   
                            $prop.='<li><span>'.T_('unidad/es disponible').'</span>'.$row['units'].'</li>'; 
                            $prop.='</div>';
                            $prop.='<div class="threebox left">';
                            if((boolean)$row['negotiation']){
                            $prop.='<li>'.T_('precio disponible a').'<strong> '.T_('negociaci&oacute;n').'</strong></li>';  
                            }
    
                            if((boolean)$row['for_rent'] ){
                                    if($row['property_type'] == 'development'){
                                    $prop.='<li><span><strong>'.T_('en renta desde:').'</strong></span> $ '.number_format($row['min_rent']).' '.T_('hasta').' '.$row['max_rent'].'</li>';   
                                    }else{
                                    $prop.='<li><span><strong>'.T_('renta:').'</strong></span> $ '.number_format($row['rent_price']).' '.$row['currency_type'].'</li>'; 
                                    }
    
                                }
                                if((boolean)$row['for_sale'] ){
                                    if($row['property_type'] == 'development'){
                                    $prop.='<li><span><strong>'.T_('en venta desde:').'</strong></span> $ '.number_format($row['min_sale']).' '.T_('hasta').' '.$row['max_sale'].'</li>';   
                                    }else{
                                    $prop.='<li><span><strong>'.T_('venta:').'</strong></span>  $ '.number_format($row['sale_price']).' '.$row['currency_type'].'</li>';    
                                    }
                                }
                                if((boolean)$row['for_vacational'] ){
                                $prop.='<li><span><strong>'.T_('renta vacacional:').'</strong></span> $ '.number_format($row['min_price']).'  / $ '.number_format($row['mid_price']).' / $ '.number_format($row['hig_price']).' '.$row['currency_type'].'</li>';    
                                }
                                $prop.='<li><span>'.T_('Tipo de propiedad').'</span><strong>'.($row[property_type]=='development'?T_('desarrollo'):$row['category']).' </strong></li>'; 
                                if($row[property_type]=='inventory'){
    
                                $prop.='<li><strong>'.T_('Pertenece a desarrollo').'</strong></li>';    
                                }
    
                            $prop.='</div>';
                            $prop.='<div class="threebox left">';
                            $prop.='<li><span>'.T_('Ba&ntilde;os:').'</span><strong> '.$row['bathrooms'].'</strong></li>';  
                            $prop.='<li><span>'.T_('Habitaciones:').'</span> '.$row['bedrooms'].'</li>';    
                            $prop.='</div>';
                            $prop.='</ul></div>';
                        $prop.='</div>';
                        $prop.='<div class="options" >
                                <ul>';
                        $prop.='<li><a rel="open" href="'.HOST.LANG.'/property/?k='.urlencode($pkey).'" title="'.T_('Ver descripcion completa de la propiedad.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-contact"></span>'.T_('ver m&aacute;s').'</a></li>';
                        $prop.='<li><a rel="note" href="#" title="'.T_('Agregar nota a esta propiedad, este mensaje es solo entre la empresa que lista la propiedad y tu como broker.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-tag"></span>'.T_('nota').'</a></li>';
                        $prop.='<li><a rel="info" href="#" title="'.T_('Ver informacion de la empresa que lista esta propiedad.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-contact"></span>'.T_('info').'</a></li>';
                        $prop.='<li><a rel="open" href="'.HOST.LANG.'/pdf/?k='.urlencode($pkey).'" title="'.T_('Descargar presentaci&oacute;n en pdf').'"  title="'.T_('Descargar presentaci&oacute;n en pdf de esta propiedad').'"><span class="ui-button-icon-primary ui-icon ui-icon-circle-arrow-s"></span>'.T_('PDF').'</a></li>';
                        $prop.='</ul>
                            </div>';
                            /*
                        $prop.='<div class="metadata threebox center shadowbox content darknessbox" >';
                            $prop.='<h3>'.$row[companyname].'</h3>';
                            $prop.='<p>'.$row[companyaddress].' </p>';
                            $prop.=' < '.$row[companyweb].' >  '.$row[companyphone].' </p>';
                            $prop.='<p><strong>'.$row[brokername].'</strong> < '.$row[brokeremail].' >  <br />'.$row[brokerphone].'  &mdash; '.$row[brokermobile].'</p>';
                            $prop.='<em>MLS-'.$row['id'].' </em>: <strong>c. '.$row[commission].'</strong>';
                        $prop.=' </div>'; */
                    $prop.=' </div>';
                }
                echo $prop;
        ?>
            </div>
    
        <?php
            echo $nav;  
        }else{
            message(T_('Wow!, lo sentimos no hay propiedades para mostrar'),'warning');
        }
    ?>
    </div>
    

    提示:1-使用模板将PHP代码与HTML代码分开
    2-print time()生成执行前和执行后的时间

    例如:

      <?
    
      $start=time();
      some code here 1 ,,,,,,,,
      $after1=time();
      $total1=$after1-$start;
      echo "total time for execution this part:  ".$total1
    
     ?>
    
    
    
    多个感叹号肯定是精神不正常的标志。而且你的文章很不连贯。我很难理解你想要什么。对不起,我不会说英语!:你为什么要加密任何东西?模糊的安全性根本不是安全性。在URL中使用真实的ID,并验证当前用户是否有权对该ID执行该操作。仅使用外观不同的“加密”ID替换ID而不验证权限是不安全的。这是测试的好主意。我在整个脚本中实现了它