简体   繁体   English

这导致我的页面加载非常慢还是根本没有?

[英]This is causing my page to load very slow or not at all?

I just updated from php 5.3.4 to 5.3.8. 我刚从PHP 5.3.4更新到5.3.8。 After the update it seems that all my code that includes try{ causes my page to hang and use up all my server memory. 更新后,似乎所有包含try {的代码都导致我的页面挂起并用完了我所有的服务器内存。

if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){
$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');
try{
$response = @new SimpleXMLElement($xml);

foreach($response as $field=>$value){
$result[(string)$field] = (string)$value; }
return $result;
}
catch(Exception $e){ $this->errors[] = $e->getMessage();
return;
}
}

This also causes a major issues 这也会引起重大问题

<?php

try{
$gt = new Gtranslate;
$gt->setRequestType('curl');

$SQL = "SELECT * FROM PAGE_CONTENT WHERE live_page = '1'";
$result = mysql_query( $SQL );
while( $row = mysql_fetch_array( $result ) ) {
$page_id_sub = $row["page_id"];
$page_title = $row["page_title"];
$page_permalink = $row["page_permalink"];

if(empty($mylang)){
echo "<a href='/$permalink/$page_permalink.html'>$page_title</a> |";
}
else {
$page_trans = $gt->$mylang("$page_title");
echo "<a href='/$permalink/$page_permalink.html'>$page_trans</a> |";
}
}
}
catch (GTranslateException $ge){
echo $ge->getMessage();
}
?>

This probably has very little to do with try and much more to do with your remote requests (ie file_get_contents() and $gt->$mylang() ). 这可能与try无关,而与您的远程请求(即file_get_contents()$gt->$mylang() )有更多关系。

As a benchmark, remove those lines and see how your page performs. 作为基准,删除这些行,然后查看页面的性能。 If they are indeed the culprit, you may want to consider caching their response or some other approach so your not making the request on every page load. 如果确实是他们的罪魁祸首,则可能要考虑缓存他们的响应或其他方法,以使您不必在每次页面加载时都发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM