Doctrine 1.2 水合作用 HYDRATION_RECORD 失败,但适用于 HYDRATION_ARRAY

发布于 2024-11-30 04:16:13 字数 3118 浏览 1 评论 0原文

我有一个代码可以在 Doctrine_Core::HYDRATION_ARRAY 中完美运行,但在 Doctrine_Core::HYDRATION_RECORD 中崩溃。该页面加载大约两分钟,并显示标准浏览器错误消息,类似于

Connection to the server was lost during the page load.

(我有本地化的浏览器,所以这不是确切的错误消息,而是翻译的)。

使用 mysql 命令行 Show processlist 输出

+-----+--------+-----------------+--------+---------+------+-------+------------------+
| Id  | User   | Host            | db     | Command | Time | State | Info             |
+-----+--------+-----------------+--------+---------+------+-------+------------------+
| 698 | root   | localhost:53899 | NULL   | Query   |    0 | NULL  | show processlist |
| 753 | *user* | localhost:54202 | *db1*  | Sleep   |  102 |       | NULL             |
| 754 | *user* | localhost:54204 | *db2*  | Sleep   |  102 |       | NULL             |
+-----+--------+-----------------+--------+---------+------+-------+------------------+

代码本身:

 $q = Doctrine_Query::create()
        ->select("fc.*")
        ->from("Card fc")
        ->leftJoin("fc.Fact f")
        ->where("f.deckid=?", $deck_id);
  $card = $q->execute(array(), Doctrine_Core::HYDRATE_RECORD);
  //Commenting the above line and uncommenting below line leads to an error
  //$card= $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

所以我认为该查询未填充正确的 SQL。然而,$q->getSqlQuery() 输出正确的 SQL,如果通过命令行或 phpMyAdmin 执行,该 SQL 可以完美运行。

服务器配置:

Apache/2.2.4 (Win32) mod_ssl/2.2.4 OpenSSL/0.9.8k mod_wsgi/3.3 Python/2.7.1 PHP/5.2.12
Mysql 5.1.40-community

一切都在本地主机上运行,​​因此这不是连接问题。

该特定查询的数据量非常小 - 大约十几条记录,因此与内存或时间限制无关。 safe_modeoffdisplay_errorsonerror_reporting6135< /代码>。

有人可以指出我缺少的一些提示或警告吗?

更新:最奇怪的是它有时会与HYDRATION_RECORD一起使用。

UPDATE2:当我尝试从查询中获取某些内容时,例如getFirst(),它崩溃了。没有获取它就可以工作,但我真的不需要一个无法获取数据的查询表单。

UPDATE3:我已经解决了这个问题,但我仍然对发生的事情感兴趣。

更新4:

Sql查询:

SELECT f.id AS f__id, f.createdat AS f__createdat, f.updatedat AS f__updatedat,
    f.flashcardmodelid AS f__flashcardmodelid, f.source AS f__source, 
    f.content AS f__content, f.md5 AS f__md5 
FROM flashcard f 
LEFT JOIN fact f2 ON f.id = f2.flashcardid AND (f2.deleted_at IS NULL) 
WHERE (f2.deckid = 19413)

输出:

f__id   f__createdat            f__updatedat            f__flashcardmodelid     f__source           f__content
245639  2011-08-05 20:00:00     2011-08-05 20:00:00     179                     jpod lesson 261     {"source":"\u7f8e\u5473\u3057\u3044","target":"del... 

所以,查询本身没问题,数据按预期受到影响。您需要模型定义吗?

更新 5 当使用 HYDRATE_RECORD 运行查询时,httpd.exe 消耗 100% 的 CPU 核心之一。

最终更新 不知道为什么,但现在它可以工作了......没有改变任何东西。当我对这个问题悬赏时,看起来它只是在等待。 :) 但是,由于我已经悬赏了,所以任何关于 HYDRATE_ARRAY 和 HYDRATE_RECORD 之间可能导致脚本崩溃的区别的想法都是值得赞赏的。

I have a code that runs perfectly with Doctrine_Core::HYDRATION_ARRAY, but crashes with Doctrine_Core::HYDRATION_RECORD. The page is loading for about two minutes and shows standard browser error message, which is something like

Connection to the server was lost during the page load.

(I have localized browser, so that's not the exact error message, but translated).

Using mysql command line Show processlist output

+-----+--------+-----------------+--------+---------+------+-------+------------------+
| Id  | User   | Host            | db     | Command | Time | State | Info             |
+-----+--------+-----------------+--------+---------+------+-------+------------------+
| 698 | root   | localhost:53899 | NULL   | Query   |    0 | NULL  | show processlist |
| 753 | *user* | localhost:54202 | *db1*  | Sleep   |  102 |       | NULL             |
| 754 | *user* | localhost:54204 | *db2*  | Sleep   |  102 |       | NULL             |
+-----+--------+-----------------+--------+---------+------+-------+------------------+

The code itself:

 $q = Doctrine_Query::create()
        ->select("fc.*")
        ->from("Card fc")
        ->leftJoin("fc.Fact f")
        ->where("f.deckid=?", $deck_id);
  $card = $q->execute(array(), Doctrine_Core::HYDRATE_RECORD);
  //Commenting the above line and uncommenting below line leads to an error
  //$card= $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

So I think that query is not populated with correct SQL. Hovewer, $q->getSqlQuery() outputs the correct SQL that runs perfectly if executed via command-line or phpMyAdmin.

Server configuration:

Apache/2.2.4 (Win32) mod_ssl/2.2.4 OpenSSL/0.9.8k mod_wsgi/3.3 Python/2.7.1 PHP/5.2.12
Mysql 5.1.40-community

Everything runs on localhost, so that's not a connection issue.

The amount of data for that specific query is very small - about a dozen records, so it's nothing to do with memory or time limits. safe_mode is off, display_errors is on ,error_reporting is 6135.

Could somebody point to some hints or caveats I'm missing?

UPDATE: what's most weird that it works with HYDRATION_RECORD from time to time.

UPDATE2: it crashes when I'm trying to fetch something from the query, e.g. getFirst(). With no fetching it works, but I really don't need a query form which I can't fetch data.

UPDATE3: I've workarounded this issue, but I'm still interested, what's going on.

Update 4:

Sql query:

SELECT f.id AS f__id, f.createdat AS f__createdat, f.updatedat AS f__updatedat,
    f.flashcardmodelid AS f__flashcardmodelid, f.source AS f__source, 
    f.content AS f__content, f.md5 AS f__md5 
FROM flashcard f 
LEFT JOIN fact f2 ON f.id = f2.flashcardid AND (f2.deleted_at IS NULL) 
WHERE (f2.deckid = 19413)

Output:

f__id   f__createdat            f__updatedat            f__flashcardmodelid     f__source           f__content
245639  2011-08-05 20:00:00     2011-08-05 20:00:00     179                     jpod lesson 261     {"source":"\u7f8e\u5473\u3057\u3044","target":"del... 

So, the query itself is OK, data fectched as expected. Do you need models definition?

Update 5 When running query with HYDRATE_RECORD httpd.exe consumes 100% of one of the CPU cores.

Final Update Don't know why, but now it works... Haven't changed anything. Looks like it just was waiting when I place a bounty on this question. :) But still, as I already have placed a bounty, any idea of what's the difference between HYDRATE_ARRAY and HYDRATE_RECORD that might crash the script is appreciated.

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

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

发布评论

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

评论(2

明天过后 2024-12-07 04:16:13

当以某种方式(print_rvar_dump 等)转储整个记录集或仅单个记录时,我看到了类似的行为。这是因为 Doctrine 使用了高度结构化的类层次结构,其中包含大量循环引用。当您使用 Doctrine_Core::HYDRATION_ARRAY 时,这显然是不正确的。

因此,任何提到的函数(但我认为这可以通过其他方式来重现)将开始无限循环,导致 100% cpu 使用率,直到达到终止点。

不知道这对您的情况是否有帮助。

I've seen a similar behavior when dumping in some way (print_r, var_dump, and so on) the whole record set or just a single record. This is caused by the fact that Doctrine uses an high structured class hierarchy which contains a lot of circular references. This obviously is not true when you use Doctrine_Core::HYDRATION_ARRAY.

So any of the mentioned functions (but I think that can be some other way to reproduce that) will begin an endless loop which causes 100% cpu usage until it reaches a kill point.

Don't know if this can help in your case.

茶底世界 2024-12-07 04:16:13

我在 Doctrine 1.2 中也遇到过类似的问题,发现 PHP 由于超出内存限制或执行时间而报告了 FATAL 错误,有时这种情况甚至导致 PHP 导致分段错误。

您可以在 Apache 错误日志文件中找到这些错误。在我的 OS X 机器上,这些文件位于 /var/log/apache2/error_log 中。您可以在 PHP 配置中增加允许的内存或最大执行时间。

就我而言,这是由于从数据库中获取的记录量过多导致内存消耗过多造成的。有时,滋润 Doctrine_Records 似乎是一件相对困难的事情。

只是出于好奇,您期望结果中有多少行?

I have had a similar issue with Doctrine 1.2, and found out that PHP reported a FATAL error due to exceeding memory limit or execution time, or sometimes the situation even got PHP to cause a segmentation fault.

You can find these errors in your Apache error log file. On my OS X box those files are in /var/log/apache2/error_log. You can increase the allowed memory or max execution time in your PHP configuration.

In my case, it was caused by the amount of records that was fetched from the database that caused excessive memory consumption. Hydrating Doctrine_Records seems to be a relatively tough thing to do some times.

Just out of curiousity, how many rows do you expect in your result?

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