这导致我的页面加载速度非常慢或根本不加载?

发布于 2024-12-11 19:23:59 字数 1296 浏览 0 评论 0原文

我刚刚从 php 5.3.4 更新到 5.3.8。更新后,似乎我所有包含 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;
}
}

这也引发了一个重大问题

<?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();
}
?>

I just updated from php 5.3.4 to 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.

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();
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断爱 2024-12-18 19:23:59

这可能与 try 关系不大,而与您的远程请求关系更大(即 file_get_contents()$gt->$mylang() )。

作为基准,删除这些行并查看页面的性能。如果他们确实是罪魁祸首,您可能需要考虑缓存他们的响应或其他一些方法,这样您就不会在每个页面加载时发出请求。

This probably has very little to do with try and much more to do with your remote requests (i.e. file_get_contents() and $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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文