0

Simple HTML Domを使用しています。以下を実行しようとしています:(WAMPを使用)

$doc = file_get_html('http://www.scoop.it/t/curate-your-personal-learning-environment?page=3');
$comments = array();
$CommentList = $doc->find('#commentList div[class=commentContainer]');
if (count($CommentList) > 0)
    var_dump($CommentList);
foreach ($CommentList as $comment)
{
    $text = $comment->find('span[class^=author]');
    $comments[] = $this::ctrim($text[0]->innertext);
}

foreach ループをコメントアウトすると、正常に実行されます。そうしないと、Apache がクラッシュします。

1 つの重要な注意: foreach ループの内部をコメント アウトすると、それでもクラッシュします。配列に有効なアイテムがあることを確認するために、var ダンプを追加しました。

編集:

Apache ログ:

[Tue Jul 10 16:53:53 2012] [notice] Parent: child process exited with status 255 -- Restarting.
[Tue Jul 10 16:53:53 2012] [notice] Apache/2.2.22 (Win64) PHP/5.3.13 configured -- resuming normal operations
[Tue Jul 10 16:53:53 2012] [notice] Server built: May 13 2012 19:41:17
[Tue Jul 10 16:53:53 2012] [notice] Parent: Created child process 5568
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Child process is running
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Acquired the start mutex.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting 64 worker threads.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting thread to listen on port 80.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting thread to listen on port 80.
4

2 に答える 2

2

これはメモリリークの可能性があります:
あなたのapacheが言うので:

子プロセスはステータス255で終了しました

ここを参照してください:
PHPのメモリ不足-Apacheがクラッシュしますか?

php5循環参照のメモリリークが原因で、DOMオブジェクトを作成した後、file_get_dom()を複数回呼び出す場合は、$ dom-> clear()を呼び出してメモリを解放する必要があります。

ここから:http ://simplehtmldom.sourceforge.net/manual_faq.htm#memory_leak

于 2012-07-10T14:05:04.310 に答える
1

変更してみる

$this::ctrim($text[0]->innertext);

self::ctrim($text[0]->innertext);

また

$this->ctrim($text[0]->innertext);

$obj->methodインスタンス呼び出しです。 Class::method静的呼び出しです。 $this::methodおそらく奇妙なことをします...

于 2012-07-10T12:42:06.933 に答える