Non Parsed Headers in PHP - php

There is an IIS bug that causes problems with headers when using a CGI program, and setting a redirect to a page that returns a http 302 (Object Moved). The result is that IIS doesn't parse the headers, so if you're trying to set cookies, it's not going to work. See the KB Article
It says the solution is to start the EXE CGI with -nph (Non parsed Headers) - but I'm not really sure if it works in PHP. I tried adding it to my php file and manually building headers, but that didn't work for me..
Has anyone had this problem? Any good workarounds?

I'm not entirely sure how you're seeing this bug in the modern era.
First, Q17..., er, I mean, KB176113 was published in 1997. The examples list IIS 2.0 as the product affected, and the article itself claims only versions 3-5 are affected. Unless you're running your site on Windows 2000, you aren't using IIS5. Both the article and a bit of time in Google suggests that this problem is entirely fixed in IIS6 and later.
Second, the bug impacts only CGI scripts. If you are using PHP with IIS, then you are either using the ISAPI DLL (and if you are, I'm so sorry), or you're using FastCGI, which despite having three letters in common, is not actually CGI. Nobody has run PHP in CGI mode on IIS since...
You aren't using IIS5, are you?
Okay, if you aren't on IIS7, you might not be running in FastCGI mode. You should totally switch to FastCGI with modern PHP versions. Microsoft spent a lot of time and effort getting PHP and FastCGI playing nicely with IIS.
Third, setting cookies mid-redirect has been buggy in every browser on every platform at one time or another. Are you sure that the cookie header isn't actually being sent? Check your browser's development tools.

Prefixing the PHP file with nph-, not -nph - solved this issue for me.
e.g. nph-test.php

Related

can't use php in html (mixing)

I would like to set up a small nginx server on my pi.
So far, html and php5 are working, but if I make a mixing, lets say:
<p>It is <?php echo time();?> UTC </p>
It would show me:
It is UTC
But if I put a index.php in root with echo phpinfo(); (index.php comes before index.html)
I got no error at all.
I followed this tutorial:
Is there anything else to install in order to use mixings?
I installed Rasbian as OS.
I am definitely not a pro, any help will be very appreciated.
Some versions of PHP are not compatible with certain versions of web servers, at least in Apache. I have next to zero experience in nginx, but if I'm not mistaken it's more commonly used for CGI, being event-based and not process-based. CGI still has it's place for some things, but I've found using MySQL more secure, and MSSQL more secure still.
On that note, you might prefer installing Apache over nginx, unless you have specific reason otherwise: I'm not sure how well developed nginx is on the RasPi, but I know many people use Apache to run web servers on it. If you're sure about using nginx, make sure there's no errors when you run the line from that page [sudo apt-get install php5-fpm].
Your issue itself seems that the PHP is not parsing. HTML will process and HTML between carrots (< and >), and not show that output to the user. However, unless PHP is working, it still is visible if you view source. To make sure PHP is installed, view the page source and see if you can see that php code. If you can, PHP isn't installed or working. If it doesn't show up, there's likely a problem with the compatibility of the server. Also, some PHP code ends up deprecated on newer versions, while some instructions are new. Make sure your issue is you're using correct code/syntax for your installed PHP version.
Lastly, but possibly most importantly: Make sure you're following the "TEST THE WEB SERVER" of your tutorial properly, and visit it from ANOTHER computer. If you try from the same IP address, it can result in loopback, where PHP won't parse for the same IP address as the source.
I also found this resource that might lead you in the right direction.
https://serverfault.com/questions/593677/php-file-are-not-parsed-by-fastcgi-in-nginx
I know this is a long answer, but it's a good way to troubleshoot with logic and understanding of how it works.
What is the extension of the file .php or .html ? It should be of type .php when you are using Php script in a file with html ie your file should be saved with extension .php.

How can I get program changes in PHP script to appear immediately?

This is probably completely obvious to somebody.
I'm using PHP on Windows 2008 Server R2 and IIS 7. FastCGI, PHP V5.3.
When I make a program change, I have to repeatedly change the file and re-save a good few times before the code recompiles and my edits are reflected. This is getting seriously annoying.
I've read about bytecode caching APC or Wincache etc. in the PHP manual, but as far as I can tell there is nothing installed.
Is there a standard bytecode cache? How do I disable it?
If not, what else could be causing this?
Thanks for your help.
P.S. IIS 7 Output caching is switched off (unticked) for both User and Kernel on this website instance.

HipHop-Php VM and auto_prepend

Does anyone know if it is possible to include an auto_prepend file with HipHop hhvm (latest version)?
I don't see in the options or the documentation anything about this feature.
No, there is currently no way to do this. I've love to get a pull request from you though :)
Support for auto_prepend_file and auto_append_file was added in HHVM 3.1.0 (Released 2014). These behave the same way as their Zend PHP counterparts.
If running an older HHVM version, there was (and still is) also the request_init_document setting is similar auto_prepend_file in that it executes before the main script for this request executes.
However, it has two important differences:
The RequestInitDocument will not run once before every single web request. Instead, HHVM runs request_init_document only once a longer-lived thread. The state of the virtual machine after request_init_document completed is captured in a snapshot and then restored at the start of multiple future requests, until it gets recycled and recreated.
HHVM 3.22.0 - Server Flow Documentation
It applies only to web requests, not CLI. https://github.com/facebook/hhvm/issues/1323

How to install PHP in IIS 7.5, Windows Server 2008 R2 (64bits)

In http://windows.php.net/downloads I couldn't find any x64 built for download.
Further I have to choose among "Thread Safe" and "Non Thread Safe" with no explanation whether one is safer than the other or it performs better. The install.txt inside the available ZIPs for download seems out-dated an it doesn't mention anything about this.
In http://php.net/manual/pl/install.windows.iis7.php they don't say a word about it either...
Another doubt is once I know what to download (and why), should it be setup as a FastCGI module or as an ISAPI extension?
(My experiences running PHP under IIS)
I believe that you should set up PHP as a FastCGI module - I don't think you are able to set up PHP as an ISAPI extension. You can set up PHP either using FastCGI or ISAPI - It may be that ISAPI is faster than FastCGI. There is a guide on setting up IIS using ISAPI here:
http://www.lazynetworkadmin.com/knowledgebase-mainmenu-6/2-windows/141-install-php-on-server-2008-r2
Searching google reveals a lot of pages discussing the thread safe vs non thread safe argument if you want to know the detail, however the short version is that the non thread safe version is faster, but the thread safe version is safer. You should choose the thread safe version for now unless you have a performance problem and know that your app is going to run correctly under the non thread safe binaries.
Finally, there isn't really any need for x64 binaries when running PHP as a FastCGI application - php runs as a separate process and so the x86 binaries will run fine on a x64 web server, and most normal php applications will have no need for an address space above 4GB as to scale IIS can simply start additional php processes.
When configuring your FastCGI extension you need to point it at the php-cgi.exe executable in the php installation directory.
I often use FastCGI when setting up PHP on IIS. It is moreso habit than anything else. While I did read over many of the other articles posted and it does appear that ISAPI has many advantages I thought I'd add a link to setting up FastCGI for those who want to go that route. I've used it and never had any issues with moderate request traffic.
Anyway here's a link to an article with screenshots on setting up PHP via FastCGI on IIS 7.5.
Click here to visit the article.

What do I need to run PHP applications on IIS?

Having been a PHP developer on LAMP servers for quite a while, is there anything that I will need to take into consideration while preparing an application for IIS on windows.
Make sure you get the FastCGI extension for IIS 6.0 or IIS 7.0. It is the single most important thing you can have when running PHP under IIS. Also this article should get you setup:
http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/
Everything beyond this is simple, MySQL and what not.
We just rolled out PHP 5.2.6 + FastCGI on our shared hosting platform without any problems. As long as you follow the steps outlined in the article Nick linked to then you should be just fine.
My only additional piece of advice would be to forget about using the fcgiconfig.js script to modify the fcgiext.ini file, it's more of a hindrance than a help. Just edit it by hand, you also learn more about how it works.
If you're installing PHP onto IIS 7 then this link should be worth a read though:
Using FastCGI to Host PHP Applications on IIS 7
#pix0r
That actually annoyed the hell out of me too and nothing came close to Apache mod_rewrite. Because they all have this overly complex XML structure. So I actually took the time and wrote my own rewriter for IIS 6.0 and IIS 7.0. Non-.NET applications only works in IIS 7.0.
http://www.managedfusion.com/products/url-rewriter/
http://www.codeplex.com/urlrewriter
One of the major sticking points I've had with IIS is the lack of Apache's mod_rewrite. There are other work-arounds and work-alikes depending on what you're doing, but just keep in mind that you'll need to change things up a bit to work with IIS if you're using mod rewrite extensively.
Since you're moving from LAMP (a somewhat cool acronym) to WIMP (a less cool one), you may need to mentally affirm yourself. Otherwise, I've had very little trouble with PHP on Windows.
ISAPI rewrite (http://www.isapirewrite.com/) is $99 and has worked very well for me for URL rewriting.
Why not go with Apache on Windows?
If your using iis 7 keep an eye on this project, http://phpmanager.codeplex.com/.

Categories