1

Minecraft サーバー用のコンソール ビューアーを作成していますが、ブラウザーにテキストを表示するだけでよい段階になると、次のエラーが表示されません。

致命的なエラー: C:\xampp\htdocs\testingfile.php 行 17 で、134217728 バイトの許容メモリ サイズが使い果たされました (36 バイトを割り当てようとしました)

ファイルが大きすぎて表示されないと思いますか?ファイルは約4.5MBです。ファイルから最新の 10 行を表示したいと考えています。

これが私のコードです:

    <?php

// define some variables
$local_file = 'C:\Users\Oscar\Desktop\worked.txt';
$server_file = 'NN7776801/server.log';
$ftp_server="Lol.Im.Not.Thick";
$ftp_user_name="Jesus";
$ftp_user_pass="ReallyLongPassWordThatYouWontGuessLolGoodLuckMateGuessingThisPass";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    $contents = file($local_file); 
    $string = implode($contents); 
    echo $string;


    for ($i = 0; $i < 6; $i++) {
    echo $local_file[$i] . "\n";
}
}
else {
    echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);

?>
4

2 に答える 2

0

最後の 10 行だけが必要な場合は、tail を使用できます

$lines = `tail -n 10 $local_file`;

fseek を使用して最後の数行を取得する方法に関する情報もここにあります。

于 2013-04-24T19:28:30.537 に答える
0

php.iniページの実行が停止しないように、変数で次の値を増やします。

max_input_time
memory_limit
max_execution_time

10 行を取得するには、次のようなものを試すことができます。

$filearray = file("filename");
$lastfifteenlines = array_slice($filearray,-15);

または関数を使用して:

function read_last_lines($fp, $num)
{
    $idx   = 0;

    $lines = array();
    while(($line = fgets($fp)))
    {
        $lines[$idx] = $line;
        $idx = ($idx + 1) % $num;
    }

    $p1 = array_slice($lines,    $idx);
    $p2 = array_slice($lines, 0, $idx);
    $ordered_lines = array_merge($p1, $p2);

    return $ordered_lines;
}

// Open the file and read the last 15 lines
$fp    = fopen('C:\Users\Oscar\Desktop\worked.txt';', 'r');
$lines = read_last_lines($fp, 10);
fclose($fp);

// Output array 
 echo '<pre>'.print_r($my_array).'</pre>';

コンテンツを印刷するには、これを追加します。

$withlines= implode ("<br>\n",$my_array); //Change $my_array with the name you used!
echo $withlines;
于 2013-04-24T18:37:25.730 に答える