2016-09-05 32 views
1

是否可以知道使用php發送到客戶端瀏覽器的字節數?我的頁面是動態創建的。所以尺寸不固定。
謝謝如何知道發送給客戶端的字節數

+0

可能重複的答案:http://stackoverflow.com/questions/1507985/php-determine-how-many-bytes-sent-over-http –

+0

@LandelinDelcoucq我不認爲這個問題涵蓋OP的用例.. – fvu

+0

出於興趣,你爲什麼想知道尺寸? – RiggsFolly

回答

1

你可以在你的web服務器的訪問日誌文件中看到這個。

但你也可以編寫一些PHP來得到這樣一個答案:

ob_start(); 

echo "your content" 

$data = ob_get_contents(); 

$size = strlen($data); 

還看到:Measure string size in Bytes in php

+0

@fuv代碼工作:) 謝謝 –

3

使用PHP的output buffering

// start output buffering 
ob_start(); 

// create your page 

// once the page is ready, measure the size of the output buffer 
$length = ob_get_length(); 
// and emit the page, stop buffering and flush the buffer 
ob_get_flush(); 

像往常一樣用PHP,這些功能在標準文檔中有很好的文檔記錄,不要忘記閱讀用戶貢獻的註釋。

+0

ob_get_length(),很好! – Michael

相關問題