Love the !bang syntax on http://duckduckgo.com
PHP gzread loop problem SOLVED!
Just been dealing with an annoying problem whereby reading a remote compressed .gz file with PHP would get stuck in a loop. I found a workaround...
The solution
This won't be very interesting or useful to anyone except other developers I'm afraid but I thought it was worth a quick blog post to help others. Essentially I was reading a remote gz file using gzread and streaming it into a local file;
while (!gzeof ($in_file)) {
$buffer = gzread ($in_file, 4096);
fwrite ($out_file, $buffer, 4096);
}
But that was just getting stuck in a loop for some reason. I have to say I didn't ever work out why (bug in my coding or bug in PHP), but I did find a workaround by using this method instead:
while ($line = gzgets($zh,1024)) {
fwrite($fc,$line);
}
Other web developers beware! Hope this helps.