php с gz контентом

12
AlExTeam
На сайте с 12.08.2010
Offline
34
#11
admak:
Никак.
Если хотите заголовок, то придется разжимать и снова сжимать.

Получится ли блоками? Сжать и выдать заголовок <html>.....<body>, сделать его вывод, потом выдать сжатый файл, и затем выдать сжатый </body></html>?

Просто никогда не игрался со сжатием, хочу узнать нюансы у сведущих. 🚬

Internet killed the video star
DyaDya
На сайте с 11.04.2007
Offline
147
#12

Нифига так не выйдет.

Попробуйте сделать два независимых архива. Затем объединить их в один файл. И открыть. Получится?

Выбирайте качественный хостинг (http://vashmaster.ru/informaciya/o_poleznyh_programmah/news83.php) и продвигайте сайты в СЕОПУЛЬТ (http://seopult.ru/ref.php?ref=72b5ed9561fe66a1). А на «SAPE» я в обиде :) Не упрекайте за очепятки, пишу вслепую (http://ergosolo.ru/) и также делаю сайты (http://www.vashmaster.ru/) ;)
AlExTeam
На сайте с 12.08.2010
Offline
34
#13

имхо нет

Придется таки напрягать сервер.

AlExTeam добавил 26.09.2010 в 23:33

Вот что накопал

<?

// Start the output buffer

ob_start();

ob_implicit_flush(0);

// Output stuff here...

print("I'm compressed!\n");

$contents = ob_get_contents();

ob_end_clean();

// Tell the browser that they are going to get gzip data

// Of course, you already checked if they support gzip or x-gzip

// and if they support x-gzip, you'd change the header to say

// x-gzip instead, right?

header("Content-Encoding: gzip");

// Display the header of the gzip file

// Thanks ck@medienkombinat.de!

// Only display this once

echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";

// Figure out the size and CRC of the original for later

$Size = strlen($contents);

$Crc = crc32($contents);

// Compress the data

$contents = gzcompress($contents, 9);

// We can't just output it here, since the CRC is messed up.

// If I try to "echo $contents" at this point, the compressed

// data is sent, but not completely. There are four bytes at

// the end that are a CRC. Three are sent. The last one is

// left in limbo. Also, if we "echo $contents", then the next

// byte we echo will not be sent to the client. I am not sure

// if this is a bug in 4.0.2 or not, but the best way to avoid

// this is to put the correct CRC at the end of the compressed

// data. (The one generated by gzcompress looks WAY wrong.)

// This will stop Opera from crashing, gunzip will work, and

// other browsers won't keep loading indefinately.

//

// Strip off the old CRC (it's there, but it won't be displayed

// all the way -- very odd)

$contents = substr($contents, 0, strlen($contents) - 4);

// Show only the compressed data

echo $contents;

// Output the CRC, then the size of the original

gzip_PrintFourChars($Crc);

gzip_PrintFourChars($Size);

// Done. You can append further data by gzcompressing

// another string and reworking the CRC and Size stuff for

// it too. Repeat until done.

function gzip_PrintFourChars($Val) {

for ($i = 0; $i < 4; $i ++) {

echo chr($Val % 256);

$Val = floor($Val / 256);

}

}

?>

теперь вопрос в следующем:

какая функция жрет меньше ресурсов сервера, gzuncompress() или crc32()???

(подозрение есть что таки вторая)

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий