<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 捕獲輸出 除非你開發的是非常簡單的控制臺應用, 否則你應該不希望php腳本代碼產生的輸出 直接被扔到激活的終端上. 捕獲這些輸出和你剛才用以覆寫啟動處理器的方法類似. 在sapi_module_struct中還有?些有用的回調: ````c typedef struct _sapi_module_struct { ... int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC); void (*flush)(void *server_context); void (*sapi_error)(int type, const char *error_msg, ...); void (*log_message)(char *message); ... } sapi_module_struct; ```` #### 標準輸出: ub_write 所有用戶空間的echo和print語句產生的輸出, 以及其他內部通過php_printf()或 PHPWRITE()產生的輸出, 最終都將被發送到激活的SAPI的ub_write()方法. 默認情況, 嵌入式SAPI直接將這些數據交給stdout管道, 而不關心你的應用的輸出策略. 假設你的應用想要把所有的輸出都發送到?個獨立的控制臺窗口; 你可能需要實現?個類似于下面偽代碼塊所描述的回調: ````c static int embed4_ub_write(const char *str, unsigned int str_length TSRMLS_DC) { output_string_to_window(CONSOLE_WINDOW_ID, str, str_length); return str_length; } ```` 要讓這個函數能夠處理php產生的內容, 你需要在調用php_embed_init()之前對 php_embed_module結構做適當的修改: ````c php_embed_module.ub_write = embed4_ub_write; ```` 注意: 哪怕你決定你的應用不需要php產生的輸出, 也必須為ub_write設置?個回調. 將它的值設置為NULL將導致引擎崩潰, 當然, 你的應用也不能幸免. #### 緩沖輸出: Flush 你的應用可能會使用緩沖php產生的輸出進行優化, sapi層提供了?個回調用以通知 你的應用"現在請發送你的緩沖區數據", 你的應用并沒有義務去實施這個通知; 不過, 由于 這個信息通常是由于足夠的理由(比如到達請求結束位置)才產生的, 聽從這個意見并不會有什么壞處. 下面的這對回調函數, 以256字節緩沖區緩沖數據由引擎安排執行flush. ````c ?char buffer[256]; int buffer_pos = 0; static int embed4_ubwrite(const char *str, unsigned int str_length TSRMLS_DC) { char *s = str; char *d = buffer + buffer_pos; int consumed = 0; /* 緩沖區夠用, 直接追加到緩沖區后面 */ if (str_length < (256 - buffer_pos)) { memcpy(d, s, str_length); buffer_pos += str_length; return str_length; } consumed = 256 - buffer_pos; memcpy(d, s, consumed); embed4_output_chunk(buffer, 256); str_length -= consumed; s += consumed; /* 消耗整個傳入的塊 */ while (str_length >= 256) { embed4_output_chunk(s, 256); s += 256; consumed += 256; } /* 重置緩沖區頭指針內容 */ memcpy(buffer, s, str_length); buffer_pos = str_length; consumed += str_length; return consumed; } static void embed4_flush(void *server_context) { if (buffer_pos < 0) { /* 輸出緩沖區中剩下的內容 */ embed4_output_chunk(buffer, buffer_pos); buffer_pos = 0; } } ```` 在startup_php()中增加下面的代碼, 這個基礎的緩沖機制就就緒了: ````c php_embed_module.ub_write = embed4_ub_write; php_embed_module.flush = embed4_flush; ```` #### 標準錯誤: log_message 在啟用了log_errors INI設置時, 在啟動或執行腳本時如果碰到錯誤, 將激活 log_message回調. 默認的php錯誤處理程序會在處理顯示(這里是調用log_message回調)之前, 格式化這些錯誤消息, 使其稱為整齊的, 人類可讀的內容. 關于log_message回調, 這里你需要注意的第?件事是它并不包含長度參數, 因此它并不是二進制安全的. 也就是說, 它只是按照NULL終止來處理字符串末尾. 使用它來做錯誤報告通常不會有什么問題, 實際上, 它可以用于在錯誤消息的呈現上 做更多的事情. 默認情況下, sapi/embed將會通過這個簡單的內建回調, 發送這些錯誤消息到標準錯誤管道: ````c static void php_embed_log_message(char *message) { fprintf (stderr, "%s\n", message); } ```` 如果你想發送這些消息到日志文件, 則可以使用下面的版本替代: ````c static void embed4_log_message(char *message) { FILE *log; log = fopen("/var/log/embed4.log", "a"); fprintf (log, "%s\n", message); fclose(log); } ```` #### 特殊錯誤: sapi_error 少數特殊情況的錯誤屬于某個sapi, 因此將繞過php的主錯誤處理程序. 這些錯誤一般 是由于使用不當造成的, 比如非web應用不應該使用header()函數, 上傳文件到控制臺應用程序等. 由于這些情況都離你所開發的sapi/embed應用非常遙遠, 因此最好保持這個回調為空. 不過, 如果你非要堅持去捕獲每種類型錯誤的源, 也只需要實現?個回調函數, 并在調 用php_embed_init()之前覆寫它就可以了. ## links * [目錄](<preface.md>) * 20.4 [覆寫INI_SYSTEM和INI_PERDIR選項](<20.4.md>) * 20.6 [同時擴展和嵌入](<20.6.md>)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看