I am testing download functionality for which I have written a php script. This script reads a large file (10MB) using fopen and fread. Using fread I am reading a chunk of 10MB in a buffer and that buffer I am echoing and then flushing out using flush and ob_flush functions. So that client receives this buffer and I am able to check number of bytes received. This works fine in Chrome, FireFox and IE 8 but when I tested it in IE 9, the browser hangs and I am not able to get the proper downloaded bytes.
Can someone suggest what are the other options that we can use to test this?
define('CHUNK_SIZE', 1024*10240);
$handle=fopen("10MBFile", 'rb');
$buffer=fread($handle, CHUNK_SIZE);
echo $buffer;
ob_flush();
flush();
Regds
I had numerous strange hangups with IE9+ and apache and could fix it with adding this stuff into httpd.conf:
# Deal with user agents that deliberately violate open standards
#
<IfModule setenvif_module>
BrowserMatch "MSIE 10.0;" bad_DNT
</IfModule>
<IfModule headers_module>
RequestHeader unset DNT env=bad_DNT
</IfModule>
AcceptFilter https none
AcceptFilter http none
EnableSendfile Off
EnableMMAP off
Related
I have a PHP script that needs to process some more information in the background after returning the response.
I made it work by following this answer as well as turning off FastCGI Output Buffer:
<IfModule mod_fcgid.c>
FcgidOutputBufferSize 0
</IfModule>
It won't work without turning off FastCGI Output Buffer.
However, I only have one script that needs this. It would be nice if I can keep FastCGI Output Buffer for all other scripts.
Is it possible to just make one PHP script ignore FastCGI Output Buffer?
Maybe you can use nested Apache directives to check the request URI.
Like this:
<IfModule mod_fcgid.c>
<If "%{REQUEST_URI} == '/path/to/script.php'">
FcgidOutputBufferSize 0
</If>
</IfModule>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new to php developer and developed a website in magento 1.7.
My website take a too much time to loading.
I deleted caches , re indexing the date comprise images still take lot time for loading.
please suggest me how to optimize the loading time of my website.
thanks in advance .
Enable Output Compression
This section will turn on the apache mod_deflate module, which compresses text, css, and javascript before it is sent to the browser. This results in a smaller download size. To enable, simply uncomment the appropriate lines so that it looks like the following:
<IfModule mod_deflate.c>
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
See more at: http://docs.nexcess.net/article/optimizing-magento-performance.html#sthash.ZUpf53Fy.dpuf
Enable Expires Headers
NOTE: This does not work on Litespeed servers.
Browsers use Expires headers to determine how long a page component can be cached. Static components, like images, should have far-future expires headers, but truthfully, all page components should have expires headers. To turn this feature on, just uncomment the appropriate line and add "ExpiresActive On" right above it. See below:
#
Add default Expires header
http://developer.yahoo.com/performance/rules.html#expires
ExpiresActive On
ExpiresDefault "access plus 1 year"
- See more at: http://docs.nexcess.net/article/optimizing-magento-performance.html#sthash.ZUpf53Fy.dpuf
Reference taken from here
This has worked for me to a good extent.
Try looking at these results: http://gtmetrix.com/reports/www.fashiza.com/KLDZeYuI
It seems like you'd gain alot in this case moving some of your javascript down and checking if all of your images have:
1) defined width and height in css.
2) format optimised for the web
EDIT: You are loading almost 500kb of javascript. This is probably the main reason. Try to compress your js and decide if you really need that much.
Tips for Magento site speed up
Summary:
Enable all Magento caching layers.
Configure your web server to enable Connection Keep-Alive, enable mod_expire, gzip compression.
Enable MySQL Query caching.
Install APC or XCache to cache PHP opcode.
Install Memcache and configure Magento to store session and cache to memory.
Install third-party Full Page Cache Magento extension.
Install Varnish cache server for full page caching on system layer.
You can check detailed instruction: http://www.magentocommerce.com/boards/viewthread/36225/
1.http://www.fashiza.com/media/js/1348d08285c79d6cda3eb91987e1942f.js
is too big 100KB
minimify that
2.http://www.fashiza.com/media/css/d2d005572b30b4d004b45f21ee567278.css
is too big
3.no file:productsliderpoint
google:compress js and you will find answer
i.stack.imgur.com/eh1NR.jpg
this is not normal
Create benchmarks to measure what causes the largest time lags. This helps you to narrow down the problem, thus, gain a better understanding, as your question is too broad to enable us to help you.
REF: https://en.wikipedia.org/wiki/Content_delivery_network
A content delivery network or content distribution network is a system of computers where our website is stored so it’s data (images/videos) can be served from multiple locations.
However I dont want to use any online paid/unpaid CDN services but would like to setup CDN on my own high speed server. I did google a lot but dont see any such CDN script which i can install on my server.
I am looking for such script which can support High level cache-control.
Can you please share if you know any good CDN script developed in PHP?
This isn't done in PHP, this done in Apache.
What I've done on my own home server (that's probably what you want) is set up a cookieless sub-domain for serving content, and enable caching and GZip. The following Apache configurations are all located in a .htaccess file in the website directory.
# GZIP compression
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(eot|ico|gif|jpe?g|php|png|ttf|svg|woff)$ no-gzip dont-vary
# Fonts on a cookieless subdomain
<FilesMatch "\.(eot|ttf|svg|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
# Cookieless Static Content
<FilesMatch "\.(css|eot|ico|gif|jpe?g|js|png|ttf|svg|woff)$">
Header unset Cookie
Header unset Set-Cookie
</FilesMatch>
# Caching
ExpiresActive On
ExpiresDefault A0
<FilesMatch "\.(eot|ico|gif|jpe?g|png|ttf|svg|woff)$">
# 2 year caching for images and stuff
ExpiresDefault A31536000
Header append Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(css|js)$">
# 1 week caching for styles and scripts
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>
#Other Header Manipulation
FileETag MTime Size
Header unset X-Powered-By
AddDefaultCharset UTF-8
DefaultLanguage en-US
So long as you don't mind caching and GZip on your primary domain (which you shouldn't), just link to your cookieless content using your designated cookielesss sub-domain, and Apache takes care of the rest.
Update
I added a few things I've learned about since posting this answer, such as:
Allowing any domain to link to fonts so that they may be served without cookies.
Setting the ETAG header since it should be set.
A few other header fields that aren't bad to include/get rid of.
However, there's one last security concern to keep in mind if you're using HTTPS, and that is BREACH. To protect against this decryption technique, you can remove gzip compression from any page that displays dynamic content (GZIPping static content like static HTML, CSS, or JS is still ok). To avoid compressing a certain file type (like PHP), add it to the SetEnvIfNoCase directive near the start of this config.
Alternatively, you can keep compression enabled and use the GCM cipher method since the BREACH family of attacks only work on the CBC cipher method. As much as I hate to be "that guy", the manual is really the best reference for this if you want to get into configuring such things. It's a fairly complicated topic and the manual does a good job of explaining the basics.
I have a ajax call to somefile.php . i want the php script to do a simple task and than send back data to the user, and only than do very time consuming tasks. so i need to flush the output after the first simple task. it doesn't work, probably because i have gzip enables.
I definitely don't want to disable gzip across all the vhost, and also not in all the folder where somefile.php is. i just want to disable it for this specific file. is that possible?
EDIT:
this is what i've included in my apache conf:
<FilesMatch \.php$>
SetEnv no-gzip 1
</FilesMatch>
this is my php script:
<?php
$sucesss = #apache_setenv('no-gzip', 1);
#ini_set('zlib.output_compression', 0);
#ini_set('implicit_flush', 1);
ob_start();
for($i=0;$i<10;$i++)
{
echo 'printing...';
ob_flush();
flush();
sleep(1);
}
?>
it doesn't work. i still see all the output together after 10 seconds.
I was looking for a solutions for the same issue. This is what worked for me but unfortunately it seams NOT to be a VALID header.
<?
header("Content-Encoding: none");
?>
apache_setenv() is correct. See the documentation.
http://php.net/manual/en/function.apache-setenv.php#60530
apache_setenv('no-gzip', '1');
Your problem is that you turned on output buffering with ob_start(). Comment that out.
I've learned that apache_setenv() is only available with the PHP Apache module. It's not available when using FPM. In that case, you have to use .htaccess to turn off GZip. An example is
https://stackoverflow.com/a/36212238/148844
RewriteRule ^dashboard/index - [E=no-gzip:1]
SetEnvIf REDIRECT_no-gzip 1 no-gzip
The - means NOOP, E means set variable, 1 is the value. After redirects, the variables are renamed and prepended with REDIRECT_.
If the output is still being buffered, check if you are going through a proxy or cache. See if headers like Via: 1.1 varnish or Via: 1.1 vegur are present. They will buffer the response also.
Put this in httpd.conf
# exclude certain page requests (e.g. for requesting getMyFile.php?action=getFile&id=3 as non-compressed)
SetEnvIfNoCase Request_URI getMyFile\.php$ no-gzip dont-vary
Now I'm not making use of any compression method,just put the below between the body tag:
<link rel="stylesheet" type="text/css" href="Client/Css/all.css" />
Is it possible to use ob_start("ob_gzhandler") in PHP to compress this css file?
And how?
this is not generally done programmatically, it is handled by the web server
For apache, there's a mod_gzip or mod_deflate module that you can use.
IIS has settings that you can use.
Yes you could (when piping the files through a php script that performs the compression). But there is much more to it than simply compressing the output. You should only send compressed output to clients that support it, you should make sure you properly handle caching information/requests. Etc.
In quite some cases your webserver contains support for doing all that for you without the need of a PHP script. In case of Apache look at mod_deflate and mod_mime (directive AddEncoding).
There are several ways.
You could tell the webserver to treat the file as PHP (renaming to have a .php extension would be the simplest) and then add:
<?php
header("Content-type: text/css; charset=utf-8");
ob_start("ob_gzhandler")
?>
to the top.
You could write a PHP script that does the same thing, but reads in the CSS file instead of having it inline.
Both this options lead to caching issues - you would have to take care of the cache control HTTP headers too if you want to be sane about it.
The best option would be to forget about PHP and just configure your webserver to compress those files (using mod_deflate, mod_gzip or similar)
If you are using a newer version of the apache web server add the following to your .htaccess file:
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
What are you trying to accomplish? If you're trying to shrink components to send to the clients browser so that they're downloaded more quickly, you should be using mod_defalte. If that's not an option, you can find more here: first result from googling "gzip php css"
EDIT: I just want to point out that unless you're using an older version of Apache, you should use mod_deflate not mod_gzip.