gpt4 book ai didi

php - 如何减少这个脚本的执行时间?

转载 作者:行者123 更新时间:2023-11-29 14:54:28 25 4
gpt4 key购买 nike

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

  1. 使用 MySQL 慢速查询不会在服务器上返回更高的工作量。所以这意味着我的查询一点也不慢。也许这是因为我还没有太多数据。
  2. 安装 memcached 减少了我的一些 PHP 执行时间,有时从 5 分钟缩短到 1 或 2 分钟,但出现了一些问题。 Memcached 不会为我的用户返回新条目。显然,我是在数据库大约 1 分钟后从内存中获取数据。所以无论如何,我决定暂时不实现 memcached。与这样的人一起工作的用户并不多。反正时间过得慢。

这就是我的服务器应用程序的风景。但几天前,出于安全原因,我实现了一个新模块,为我的应用程序上的所有对象创建一个加密 key 。我为此实现了 datacrypt 类,显然它在我的笔记本电脑上的开发环境中完美运行。

我为什么来寻求帮助?使用 winCachegrind 查看 Xdebug 分析,我发现 datacrypt 的实例化执行需要 37,218 毫秒,我的一些文件显示 10 或 15 行,并且每一行都会动态生成和加密 key 。

datacrypt 类的高使用是一个问题。它用于每个脚本文件中。因此,我需要获得一个新的快速类来创建加密哈希以在我的应用程序中使用。

有谁可以推荐给我吗?或者我该怎么做才能让 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

?>

关于php - 如何减少这个脚本的执行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4983789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com