In script PHP output buffer settings ignored by server - php

I have been trying to flush the output of certain scripts to the browser on demand, but they do not work on our productions server.
For instance, I tried running the "Phoca Changing Collation tool" (find it on Google) and I don't see any output until the script finishes executing.
I've tried immediately flushing the buffer on other script that works fine on any server but this one using the following code:
echo "something";
ob_flush();
flush();
Setting "ob_implicit_flush(1);" doesn't help either.
The server is Apache 2.2.21 with PHP 5.2.17 running on Linux. You can see our php.ini file here if that will help:
http://www.smallfiles.org/download/1123/php.ini.html
This isn't the only problem we are having with the server ignoring in-script directives. The server also ignores timeout coding such as:
ini_set('max_execution_time', 900*60);
AND
set_time_limit(86400);
Script always times out at the php.ini default.
Doesn't seem to matter if script is executed in IE or Firefox.

Solved this mystery. Both of them.
To fix the output buffer problem, I needed to turn off gzip compression inside the .htaccess file, though I wish I could just do it in-script.
Here's what you should put in your .htaccess file:
<IfModule mod_gzip.c>
mod_gzip_on No
</IfModule>
SetEnv no-gzip dont-vary
To fix the script terminating without error, I checked my Apache log files and found it wasn't PHP but in the Apache configuration:
The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed
Had to increase the Apache timeout to prevent this error from making it look like my scripts were timing out. Enabling KeepAlive in Apache also helped to resolve the issue once and for all.
Hope this helps someone and thanks for everyone elses' help!

You could be loading an incorrect php.ini file, as it tends to change based on directory.
To check your loaded php.ini file, write: echo php_ini_loaded_file();, which will give you the directory it's in. see php.net
if that fails, see serverfault.com for the server stackexchange site.

Related

ERR_INCOMPLETE_CHUNKED_ENCODING Chrome Root page load

I have a website on a lamp stack with little to no extra configuration other than FallbackResource /index.php present in my root .htaccess
When I load the root page (localhost ) in Chrome I receive
GET http://192.168.163.171/ net::ERR_INCOMPLETE_CHUNKED_ENCODING VM110:1
in the chrome console after about 10 seconds. If I attempt to follow the link at VM110:1 it takes me to the top of my inline Javascript.
More information / What I've tried
This does NOT occur on any other page but root
There are no 404's in the access log nor any other abnormal codes
There are no errors appearing in the apache error log.
The error does not occur in the latest version of IE or Firefox.
It caused a problem in both my local environment and hosted. The latter has absolutely no config changes and I expect to be a near default install.
When I remove the FallbackResource directive my page loads fine without the error
In index.php the root is treated no different than any other page.
This would all be a non-issue because everything loads properly BUT it prevents javascript relying on a finished page load from working.
Any further ideas on what is causing the problem or new things I can try? I've considered moving to just using mod_rewrite but this is much simpler.
Finally found the answer while working on another site:
Before FallbackResource directive be sure to add a DirectoryIndex directive with the same file. Haven't had time to research why but it fixed my issue. I blame it on a Chrome bug or possibly Chrome being super picky because no other major browser has an issue.
I fixed this error by removing the following lines from my php5filter.conf file in the Apache configuration:
<FilesMatch ".+\.ph(p3?|tml)$">
SetInputFilter PHP
SetOutputFilter PHP
</FilesMatch>
To add to Blaine's answer (as I can't yet comment):
I believe this is an Apache configuration issue, not specific to Chrome.
I recently experienced this issue, and noted the following effects in various clients, again only with the home page:
Chrome, as stated, displayed the ERR_INCOMPLETE_CHUNKED_ENCODING error, but also didn't display the page correctly. The page continued to "load" for another 5 seconds even after all the content was visible.
A simple CURL request outputted the error curl: (18) transfer closed with outstanding read data remaining. The full HTML appeared, followed by the error after a delay.
Firefox and IE initially displayed the page incorrectly, as with Chrome, and again had the ~5 second additional loading time. However, after this period, the page suddenly reformatted itself correctly. No errors were seen in the respective developer consoles.
The solution to set the DirectoryIndex to the same location as FallbackResource resolved this for all clients.
Edit: An alternative if using mod_rewrite is to use something like RewriteRule ^$ index.php which will avoid affecting all subdirectories.
I don't know whether this is expected behaviour of Apache or a bug.
In my json response '\n' causing the issue. So after removing it, issue has been solved.

Stop Apache Blocking ETags

I have written a web application that uses someone else's API that requires ETags. I have tried this code:
header("ETagbleh: whatever");
Which works perfectly. However, when I set this:
header("ETag: whatever");
Nothing happens. I have heard that it may be Apache blocking the sending of ETags, but I'm not sure. I've done a search for ETag in my apache2.conf and can't find anything to uncomment / remove, so I came here to ask.
So, how can I stop Apache blocking my headers?
Edit: I'm using Apache 2.2.22, and I assumed that the scripting language was irrelevant, given that PHP 5.4.4, which is what I'm using, can set any other header fine.
I've had the same problem.
A very popular way to remove ETags in Apache2 is adding the following configuration:
Header unset ETag
FileETag None
Remove the first config line, if you find it in your configuration.
A bit more difficult to find is mod_include causing the problem. By default the ETag-Header is removed by this module. But you can allow it by configuration. So add something like this:
<IfModule mod_include.c>
SSIETag on
</IfModule>
See here for more information.

Apache 2 and .htaccess are downloading, not running, PHP files

I'm trying to use .htaccess files with PHP on OS X (Snow Leopard, 10.6.8), but when I go to localhost/ the browser just downloads whatever file it's lead to by the rewrite rules (rather than getting the output of the server-side execution of the PHP).
I've confirmed that PHP runs with Apache on other, simpler installations. For debugging I'm targetting check.php script so that should be good.
The web is full of guidance to hunt down and replace all AllowOverride None statements with AllowOverride All, but my apache configuration for this differs from the base OS X installation and doesn't include any of the various files with the AllowOverride None directives. I've set all of those touched by my configuration.
This same configuration runs the php scripts just fine when they're hit by the URL.
I've confirmed that mod_rewrite.so is available and loaded.
I'd appreciate help diagnosing / debugging this.
EDIT:
Also, when I hit the page from Firefox, I get a dialog saying "You have chosen to open [blank, for the index url] which is a: application/x-httpd-php5" and the choice to save or run. That x-httpd-php5 value is the string I use in the AddType directive in the .htaccess file.
Make sure Web Sharing is turned on in the preferences.

Server Signuture turn off need access to php.ini

I want to add the following settings to my server:
ServerSignature Off
ServerTokens Prod
However after research I have to add these settings in my httpd.conf or apache2.conf file. It wont work in my php.ini or .htaccess on my public webroot. If I have not got access to these two server files (httpd.conf or apache2.conf) how can I get access or is there an alternative way to get these settings to work. It is a security issue I need to sort out ASAP. Thanks
No, you can't configure Apache (as these are apache settings) via php nor any other language.
You may hide these values from showing on error pages with a little of mod_rewrite that any request to your server or web application gets directed to a php script that outputs whatever error you want.
These values are also shown in the http response headers that apache sends to the browser, so maybe you can overwrite them with php via the header function, using the optional param $bool_replace = true (which is the default value):
header("Server: IIS/6.0", true); // this will fool observers
header("X-Powered-By: Feces-Throwing-Monkey 3.14", true);
edit: Judging from a comment in php's header documentation, this works, and you should also overwrite the X-Powered-By header.

Why can't my browser see my hosted php files?

I'm sure I'm doing something dumb, but I can't tell what it is.
On my remote host, I have a subdir with a bunch of files.
When I request this directory, I can see a listing of the files within this dir.
However, if request any file suffixed .php, my browser says that the resource is not available. Firefox tells me that it can't find the file I requested.
I guess that this is a permissions issue.
For testing purposes, I have set the permissions as permissively as possible.
What could be causing this?
Resource not available (HTTP 503) depends a lot on your server configuration. If you are using a FastCGI version of PHP, have you started the FastCGI backend? If you are using Apache and mod_php, are there errors in the Apache logs?
What web server are you using? Has it been able to serve PHP files before?
if apache, make sure you have something similar to this in your config:
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
</IfModule>

Categories