久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='MxALi'><style id='MxALi'><dir id='MxALi'><q id='MxALi'></q></dir></style></legend>
    • <bdo id='MxALi'></bdo><ul id='MxALi'></ul>
      <i id='MxALi'><tr id='MxALi'><dt id='MxALi'><q id='MxALi'><span id='MxALi'><b id='MxALi'><form id='MxALi'><ins id='MxALi'></ins><ul id='MxALi'></ul><sub id='MxALi'></sub></form><legend id='MxALi'></legend><bdo id='MxALi'><pre id='MxALi'><center id='MxALi'></center></pre></bdo></b><th id='MxALi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='MxALi'><tfoot id='MxALi'></tfoot><dl id='MxALi'><fieldset id='MxALi'></fieldset></dl></div>

      <tfoot id='MxALi'></tfoot>

      1. <small id='MxALi'></small><noframes id='MxALi'>

      2. 從文件中讀取最后一行

        Read last line from file(從文件中讀取最后一行)
        • <bdo id='KQ1d2'></bdo><ul id='KQ1d2'></ul>

                  <i id='KQ1d2'><tr id='KQ1d2'><dt id='KQ1d2'><q id='KQ1d2'><span id='KQ1d2'><b id='KQ1d2'><form id='KQ1d2'><ins id='KQ1d2'></ins><ul id='KQ1d2'></ul><sub id='KQ1d2'></sub></form><legend id='KQ1d2'></legend><bdo id='KQ1d2'><pre id='KQ1d2'><center id='KQ1d2'></center></pre></bdo></b><th id='KQ1d2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KQ1d2'><tfoot id='KQ1d2'></tfoot><dl id='KQ1d2'><fieldset id='KQ1d2'></fieldset></dl></div>

                  <tfoot id='KQ1d2'></tfoot>
                1. <small id='KQ1d2'></small><noframes id='KQ1d2'>

                  <legend id='KQ1d2'><style id='KQ1d2'><dir id='KQ1d2'><q id='KQ1d2'></q></dir></style></legend>
                    <tbody id='KQ1d2'></tbody>
                  本文介紹了從文件中讀取最后一行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我遇到了一個問題.我在 Linux 機器上有一個日志,其中寫入了幾個正在運行的進程的輸出.這個文件有時會變得非常大,我需要讀取該文件的最后一行.

                  I've been bumping into a problem. I have a log on a Linux box in which is written the output from several running processes. This file can get really big sometimes and I need to read the last line from that file.

                  問題是此操作將經常通過 AJAX 請求調用,并且當該日志的文件大小超過 5-6MB 時,對服務器來說相當不利.所以我想我必須閱讀最后一行,而不是閱讀整個文件并通過它或將它加載到 RAM 中,因為那只會加載到我的盒子里.

                  The problem is this action will be called via an AJAX request pretty often and when the file size of that log gets over 5-6MB it's rather not good for the server. So I'm thinking I have to read the last line but not to read the whole file and pass through it or load it in RAM because that would just load to death my box.

                  這個操作有沒有什么優化,可以流暢運行,不傷服務器,不殺Apache?

                  Is there any optimization for this operation so that it run smooth and not harm the server or kill Apache?

                  我的其他選擇是 exec('tail -n 1/path/to/log') 但聽起來不太好.

                  Other option that I have is to exec('tail -n 1 /path/to/log') but it doesn't sound so good.

                  稍后我不想將文件放在 RAM 中,因為它可能會變得很大.fopen() 不是一個選項.

                  Later edit: I DO NOT want to put the file in RAM because it might get huge. fopen() is not an option.

                  推薦答案

                  這應該有效:

                  $line = '';
                  
                  $f = fopen('data.txt', 'r');
                  $cursor = -1;
                  
                  fseek($f, $cursor, SEEK_END);
                  $char = fgetc($f);
                  
                  /**
                   * Trim trailing newline chars of the file
                   */
                  while ($char === "
                  " || $char === "
                  ") {
                      fseek($f, $cursor--, SEEK_END);
                      $char = fgetc($f);
                  }
                  
                  /**
                   * Read until the start of file or first newline char
                   */
                  while ($char !== false && $char !== "
                  " && $char !== "
                  ") {
                      /**
                       * Prepend the new char
                       */
                      $line = $char . $line;
                      fseek($f, $cursor--, SEEK_END);
                      $char = fgetc($f);
                  }
                  
                  fclose($f);
                  
                  echo $line;
                  

                  請注意,除非您的文件以換行符結尾,否則此解決方案將重復該行的最后一個字符.如果您的文件沒有以換行符結尾,您可以將 $cursor-- 的兩個實例更改為 --$cursor.

                  Note that this solution will repeat the last character of the line unless your file ends in a newline. If your file does not end in a newline, you can change both instances of $cursor-- to --$cursor.

                  這篇關于從文件中讀取最后一行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                      1. <tfoot id='YmWo9'></tfoot>

                          <small id='YmWo9'></small><noframes id='YmWo9'>

                        • <i id='YmWo9'><tr id='YmWo9'><dt id='YmWo9'><q id='YmWo9'><span id='YmWo9'><b id='YmWo9'><form id='YmWo9'><ins id='YmWo9'></ins><ul id='YmWo9'></ul><sub id='YmWo9'></sub></form><legend id='YmWo9'></legend><bdo id='YmWo9'><pre id='YmWo9'><center id='YmWo9'></center></pre></bdo></b><th id='YmWo9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YmWo9'><tfoot id='YmWo9'></tfoot><dl id='YmWo9'><fieldset id='YmWo9'></fieldset></dl></div>
                            <bdo id='YmWo9'></bdo><ul id='YmWo9'></ul>

                          • <legend id='YmWo9'><style id='YmWo9'><dir id='YmWo9'><q id='YmWo9'></q></dir></style></legend>
                              <tbody id='YmWo9'></tbody>
                            主站蜘蛛池模板: 日本久久久久久 | 欧美精品在线免费观看 | 色婷婷激情综合 | 中文字幕视频三区 | 3p视频在线观看 | 国产91精品久久久久久久网曝门 | 国产精品色婷婷久久58 | 祝你幸福电影在线观看 | 日韩欧美电影在线 | 亚洲国产成人精品久久久国产成人一区 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 久久久www成人免费无遮挡大片 | 久久久成人动漫 | 精品国产乱码久久久久久1区2区 | 日韩欧美一级精品久久 | 91免费在线| 91av在线看 | 精品视频一区二区三区在线观看 | 亚洲 欧美 日韩 在线 | 国产欧美一级二级三级在线视频 | 天天干,夜夜操 | 黄色片在线免费看 | 亚洲精品中文字幕在线观看 | 黄色大片在线免费观看 | 国内精品视频在线 | 成人一区精品 | 国产日韩欧美在线 | 亚洲成人在线网 | av黄色在线 | 夜夜草导航| 全免费a级毛片免费看视频免费下 | 国产日韩欧美 | 亚洲一区二区三 | 亚洲美女在线一区 | 欧美日韩成人网 | 欧美日韩亚洲系列 | 怡红院怡春院一级毛片 | 日本视频免费观看 | 精精国产视频 | a级片在线观看 | 国产精品国产成人国产三级 |