谷歌翻译 Curl 耗尽 php 5.3.8 中的所有内存

发布于 2024-12-12 08:01:14 字数 853 浏览 0 评论 0原文

我一直用它来将基本网站文本翻译成不同的语言。在我更新到 PHP 5.3.8 之前它一直运行良好。它耗尽了所有内存,彻底瘫痪了我的服务器。我做错了什么?我确信我会收到很多评论:)

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 have been using this to translate basic site text in to different languages. It has worked great until I updated to PHP 5.3.8. It completely took down my server by using up all the memory. What am I doing wrong? I'm sure by saying that I'll get a lot of comments :)

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-19 08:01:14

我会像这样进行调试,以检查哪个进程卡住了。

<?php

echo "\n start: " . memory_get_usage() . "\n";

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

    echo "\n after class: " . memory_get_usage() . "\n";

    $SQL = "SELECT * FROM PAGE_CONTENT WHERE live_page = '1'";
    $result = mysql_query( $SQL );

    echo "\n after query: " . memory_get_usage() . "\n";

    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> |";
      }
    }
    echo "\n after while: " . memory_get_usage() . "\n";

  }
  catch (GTranslateException $ge){
    echo $ge->getMessage();
  }

echo "\n end: " . memory_get_usage() . "\n";

I would debug like this in order to check which process stuck.

<?php

echo "\n start: " . memory_get_usage() . "\n";

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

    echo "\n after class: " . memory_get_usage() . "\n";

    $SQL = "SELECT * FROM PAGE_CONTENT WHERE live_page = '1'";
    $result = mysql_query( $SQL );

    echo "\n after query: " . memory_get_usage() . "\n";

    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> |";
      }
    }
    echo "\n after while: " . memory_get_usage() . "\n";

  }
  catch (GTranslateException $ge){
    echo $ge->getMessage();
  }

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