0

これが昨夜はうまく機能していた理由がわかりませんが、今朝は

致命的なエラー: 行 121 の /home/twitcast/public_html/system/index.php でメモリ不足 (割り当てられた 1611137024) (1610350592 バイトを割り当てようとしました)

実行されているコードのセクションは次のとおりです

function podcast()
  {
            $fetch = new server();
            $fetch->connect("TCaster");
            $collection = $fetch->db->shows;

            // find everything in the collection
            $cursor = $collection->find();

            if($cursor->count() > 0)
            {
                $test = array();
                // iterate through the results
                while( $cursor->hasNext() ) {   
                    $test[] = ($cursor->getNext());
                }
                $i = 0;
                foreach($test as $d) {

                for ( $i = 0; $i <= 3; $i ++) {
                $url = $d["streams"][$i];   
                $xml = file_get_contents( $url );
                $doc = new DOMDocument();
                $doc->preserveWhiteSpace = false;
                $doc->loadXML( $xml); // $xml = file_get_contents( "http://www.c3carlingford.org.au/podcast/C3CiTunesFeed.xml")

                // Initialize XPath    
                $xpath = new DOMXpath( $doc);
                // Register the itunes namespace
                $xpath->registerNamespace( 'itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');

                $items = $doc->getElementsByTagName('item');    
                    foreach( $items as $item) {
                        $title = $xpath->query( 'title', $item)->item(0)->nodeValue;
                        $published = strtotime($xpath->query( 'pubDate', $item)->item(0)->nodeValue);
                        $author = $xpath->query( 'itunes:author', $item)->item(0)->nodeValue;
                        $summary = $xpath->query( 'itunes:summary', $item)->item(0)->nodeValue;
                        $enclosure = $xpath->query( 'enclosure', $item)->item(0);
                        $url = $enclosure->attributes->getNamedItem('url')->value;

                    $fname = basename($url);
                    $collection = $fetch->db->shows_episodes;

                    $cursorfind = $collection->find(array("internal_url"=>"http://twitcatcher.russellharrower.com/videos/$fname"));
                    if($cursorfind->count() < 1)
                    {


                        $copydir = "/home/twt/public_html/videos/";
                        $data = file_get_contents($url);
                        $file = fopen($copydir . $fname, "w+");

                        fputs($file, $data);

                        fclose($file);
                        $collection->insert(array("show_id"=> new MongoId($d["_id"]),"stream"=>$i,"episode_title"=>$title, "episode_summary"=>$summary,"published"=>$published,"internal_url"=>"http://twitcatcher.russellharrower.com/videos/$fname"));

                        echo "$title <br> $published <br> $summary <br> $url<br><br>\n\n";
                    }




                }

            }
            }
            }

121行目は

$data = file_get_contents($url);
4

2 に答える 2

0

単一のPHPスレッドに1.6GBのメモリ使用量を追加したいですか?メモリ制限を増やすことはできますが、私の強いアドバイスは、あなたが望むことを行う別の方法を検討することです。

おそらく最も簡単な解決策:CURLを使用してソースファイルのバイト範囲を要求できます(リモートファイルの場合、Curlを使用する方がget_file_contentsよりも賢明です)。一度に100Kを取得し、ローカルファイルに書き込んでから、次の100Kを取得して、ファイル全体がプルインされるまでファイルなどに追加できます。

ストリームを使って何かをすることもできますが、もう少し複雑になります。リモートサーバーでファイルの一部をバイト単位で取得できない場合は、これが唯一のオプションになる可能性があります。

最後に、サーバーに権限がある場合は、exec()を介して実行されるwgetなどのLinuxコマンドがあります。

于 2012-08-27T01:44:58.417 に答える
0

メモリ制限- このディレクティブを見てください。それが必要なものだとします。

または、ファイルをメモリに読み取る代わりに使用しようとする場合がありcopyます(これはビデオファイルです。私が理解しているように、多くのメモリが必要になることは何もありません):

$copydir = "/home/twt/public_html/videos/";
copy($url, $copydir . $fname);

昨夜開いたファイルが小さかったようです)

于 2012-08-27T00:50:56.570 に答える