[PHP] PHP script lag (5 secs) when declaring mime type.
Hello, I don't know for sure is this problem is only related to PHP so I hope I've posted in the right list. My problem is that with certain headers my script takes about 5 seconds before sending the page, no matter how small the file I try to load... My server : Centos Apache 2.2 PHP 5.2.9 Here's my code : test.js is only a few lines long, and if I remove the header content type the file loads instantaniously do it's not a problem with readfile. I thought about zlib gzip taking maybe a long time to load but I've changed the compression level from 6 to 1 and the file still has a the same lag. My server responds very fast for eveything else except this script. Do you have an idea what might be causing this lag ? Thanks in advance :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script lag (5 secs) when declaring mime type.
Hello, Just to say that I've got a bit further in my search : (Content-Length line removed) Has no lag... My guess is there is a problem with gzip or something that corrupts the content-length. So I'm still not sure if this is a PHP problem or an apache problem but any help would be great :) Thankyou Jsbeginner a écrit : Hello, I don't know for sure is this problem is only related to PHP so I hope I've posted in the right list. My problem is that with certain headers my script takes about 5 seconds before sending the page, no matter how small the file I try to load... My server : Centos Apache 2.2 PHP 5.2.9 Here's my code : test.js is only a few lines long, and if I remove the header content type the file loads instantaniously do it's not a problem with readfile. I thought about zlib gzip taking maybe a long time to load but I've changed the compression level from 6 to 1 and the file still has a the same lag. My server responds very fast for eveything else except this script. Do you have an idea what might be causing this lag ? Thanks in advance :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script lag (5 secs) when declaring mime type.
Thankyou, I took "application/x-javascript" directly from the apache setup for my domain so this should be correct. However I've just deactivated gzip (zlib.output_compression OFF in php.ini) and that stopped the problem. I've given you a simplified version of the script that has the exact same problem (the original one gets the mime type automaticaly and has the same problem with any files that are gziped (css, html, javascript etc... but not images.). So the problem seems to have someting to do with this line : header('Content-Length: '.filesize('test.js')); and with gzip ... I would like to be able to activate gzip again but I need to work out why I'm getting this bug first. Apache isn't installed with mod_deflate, should I look into doing this instead of turning zlib.output_compression on again ? Is there maybe a bug with PHP 5.2.9 that's causing this problem? Thankyou :) haliphax a écrit : On Thu, Mar 5, 2009 at 10:27 AM, Jsbeginner wrote: Hello, Just to say that I've got a bit further in my search : (Content-Length line removed) Has no lag... My guess is there is a problem with gzip or something that corrupts the content-length. So I'm still not sure if this is a PHP problem or an apache problem but any help would be great :) Thankyou Jsbeginner a écrit : Hello, I don't know for sure is this problem is only related to PHP so I hope I've posted in the right list. My problem is that with certain headers my script takes about 5 seconds before sending the page, no matter how small the file I try to load... My server : Centos Apache 2.2 PHP 5.2.9 Here's my code : test.js is only a few lines long, and if I remove the header content type the file loads instantaniously do it's not a problem with readfile. I thought about zlib gzip taking maybe a long time to load but I've changed the compression level from 6 to 1 and the file still has a the same lag. My server responds very fast for eveything else except this script. Do you have an idea what might be causing this lag ? Thanks in advance :) Well, have you tried using Content-Type: "text/javascript" as suggested? Is "application/x-javascript" absolutely necessary for whatever application is reading your script's output? As it has already been mentioned, Apache may be looking for your content type in some sort of lookup table, not finding it, and taking its sweet time returning control back to PHP while it grabs at straws to match.
Re: [PHP] Re: PHP script lag (5 secs) when declaring mime type.
Thankyou for the help, I will contact the script maintainer to ask him to work on this problem for future updates, and for the moment I've commented out the line that specifies the length. I suppose that it won't cause any problems with files that are sent through this script that are not gzipped (this script allows html, js, css (all compressed with gzip) as well as images that aren't compressed. From what I understand the best would be to detect if gzip is activated for each file and only allow the header to specify the length if the file is not planned to be compressed with gzip (images etc). Thanks again :) Nisse Engström a écrit : On Thu, 5 Mar 2009 19:14:20 +0100, Nisse Engström wrote: On Thu, 05 Mar 2009 15:45:35 +0100, Jsbeginner wrote: test.js is only a few lines long, and if I remove the header content type the file loads instantaniously do it's not a problem with readfile. I thought about zlib gzip taking maybe a long time to load but I've changed the compression level from 6 to 1 and the file still has a the same lag. Content-Length MUST NOT be sent when using a Transfer-Encoding (eg. gzip). See: <http://tools.ietf.org/html/rfc2616#section-4.4> And I goofed: Transfer-Encoding is the stuff that says "chunked". I was thinking of Content-Encoding. But the section I refered to also says: "If a Content-Length header field (section 14.13) is present, its decimal value in OCTETs represents both the entity-length and the transfer-length. The Content-Length header field MUST NOT be sent if these two lengths are different" [And a little further down, it mentions "that the recipient can arse it". I'm not sure quite what to make of that. :-)] - - - Come to think about it, I've written some output handlers to convert utf-8 to utf-16 or -32, which uses either 'Content-Length' or 'Transfer-Encoding: chunked' depending on the size of the output. Perhaps I should change that to always 'chunked'... /Nisse