skibulk
skibulk

Reputation: 3188

CPU intensive? PHP byte read gzip file to browser

I want to use a PHP script as an intermediary to serve a .JS.GZ file with appropriate response headers and caching headers. How much more CPU intensive is this as compared to just serving the file directly? How could I benchmark the CPU usage?

$file = fopen('autocomplete.js.gz', 'rb');
echo fpassthru($file);

Upvotes: 0

Views: 432

Answers (2)

mario
mario

Reputation: 145482

readgzfile() is the most efficient solution PHP itself has to offer. The inflate decompression algorithm itself doesn't consume much CPU power, and has only a small memory footprint as well (well normally). It's one of the most optimized zlib functions.

Upvotes: 1

powtac
powtac

Reputation: 41040

Usage of xsendfile:

<?php 
header('X-Sendfile: autocomplete.js.gz'); // does not use any PHP memory!

Upvotes: 1

Related Questions