Re: [PHP] PHP script lag (5 secs) when declaring mime type.
Jsbeginner schreef: 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 : ?php header('Content-Type: application/x-javascript'); header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? 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 ? something to do with apache, usually we we see this it's something to do with DNS lookups ... unlikely in your case. I figure it's something to do with apaches' content negotiation, possibly it looks up your content-type for some reason but ends up not recognizing it (and tries alsort of stuff before giving up and just sending the output) http://httpd.apache.org/docs/2.0/content-negotiation.html question is do you really need application/x-javascript? won't text/javascript do just fine? or does that have the same problem? ... actually does the problem occur with any value for 'Content-Type'? 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 : ?php header('Content-Type: application/x-javascript'); //header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? (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 : ?php header('Content-Type: application/x-javascript'); header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? 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.
On Thu, Mar 5, 2009 at 10:27 AM, Jsbeginner jsbegin...@monarobase.net wrote: Hello, Just to say that I've got a bit further in my search : ?php header('Content-Type: application/x-javascript'); //header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? (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 : ?php header('Content-Type: application/x-javascript'); header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? 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. -- // Todd -- 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 jsbegin...@monarobase.net wrote: Hello, Just to say that I've got a bit further in my search : ?php header('Content-Type: application/x-javascript'); //header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? (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 : ?php header('Content-Type: application/x-javascript'); header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? 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] PHP script lag (5 secs) when declaring mime type.
On Thu, Mar 5, 2009 at 11:34 PM, Jsbeginner jsbegin...@monarobase.netwrote: 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 think content-length is not a thing you have to mention. Only I have seen its required for image type data yet. 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 jsbegin...@monarobase.net wrote: Hello, Just to say that I've got a bit further in my search : ?php header('Content-Type: application/x-javascript'); //header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? (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 : ?php header('Content-Type: application/x-javascript'); header('Content-Length: '.filesize('test.js')); readfile('test.js'); ? 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] PHP script lag (5 secs) when declaring mime type.
On Thu, Mar 5, 2009 at 12:34 PM, Jsbeginner jsbegin...@monarobase.net wrote: 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 : If you use gzip'd output, does PHP automatically generate a Content-Length header? It seems to me that the value for Content-Length should be the compressed size, not the uncompressed size that you are sending. Besides - do you really need to send Content-Length? I don't usually see it sent, and the only time I've seen it make a difference is if I'm sending the file as an attachment (prompting the browser to save the file rather than displaying it). If removing the line eliminates the problem, I'd just remove the line and be done with it. Andrew -- 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.
On Thu, Mar 5, 2009 at 1:26 PM, Jsbeginner jsbegin...@monarobase.net wrote: Thankyou Andrew Ballard and 9Tel , You're welcome. However, you forgot to reply to the list. You both suggest that it's not necessory to set the Content-Length except for images etc ... well the problem is that I also need to use this script for showing images as well as css and javascript. As I understand, there is no point in using gzip to serve images since they are usually already compressed and/or not very well suited to textual compression. In fact, I suspect that if you serve a document with a Content-Type of image/gif, image/jpeg, image/png, etc., either PHP or Apache will detect that and bypass the gzip handler. (That's just a guess, though. I don't have any way at present to test that theory.) It's actually part of the dotclear blog system, it's plugin system uses a very similar code but fetching the mime type automaticaly. And it's not part of one plugin but used for all the plugins so if any plugins are installed on any dotclear installation on the server there will be a lag. Also I don't see how it would be possible to check file size after gzip ... doesn't PHP take the file and then pass it through gzip changing the size on the way ? Based on Nisse's response, I think you're better off leaving the Content-Length header out entirely (as we already suggested). I guess I will have to send an e-mail to the dotclear team to ask their advice. Thankyou. Andrew Ballard a écrit : On Thu, Mar 5, 2009 at 12:34 PM, Jsbeginner jsbegin...@monarobase.net wrote: 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 : If you use gzip'd output, does PHP automatically generate a Content-Length header? It seems to me that the value for Content-Length should be the compressed size, not the uncompressed size that you are sending. Besides - do you really need to send Content-Length? I don't usually see it sent, and the only time I've seen it make a difference is if I'm sending the file as an attachment (prompting the browser to save the file rather than displaying it). If removing the line eliminates the problem, I'd just remove the line and be done with it. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php