Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Most results I get on google is how to get both versions running simultaneously on the same server but at different URLS but that's not what I want.

I'd like, for example, to get http://localhost to run PHP4 and PHP5 at the same time on the same site. This is because I have a website that has old code from PHP4 that breaks up when executed in PHP5.

The same site also has some components written only in PHP5, so I would like to run both PHP versions at the same time in the same site.

I'm on Windows XP running Apache, I wouldn't mind switching to IIS7 if it's required.

I'm already aware of the security risks associated with this potential solution.

share|improve this question

migrated from stackoverflow.com Nov 15 '11 at 17:54

This question came from our site for professional and enthusiast programmers.

1  
Not only is this a confusing question, but even assuming what you're asking is possible, it can't be any easier than upgrading your old code. So try that instead. –  muffinista Nov 15 '11 at 16:10
add comment

1 Answer

You cannot have one PHP script executed by both the PHP4 runtime and the PHP5 runtime at the same time. There's only one interpreter running at any time. So, no execution of "these few lines and PHP4" and the "other ones over there in PHP5" and jumping back and forth between the two.

It's however possible to connect two separate scripts. Create the normal PHP output script and invoke any PHP4 code like this:

<?php
  // do some PHP5 code here
  code_here(...);

  // then invoke the script parts for PHP4
  passthru("php4-cgi.exe .../script2.php4");
   # MAYBE REQUIRES setenv("SCRIPT_FILENAME", ...); ETC. ON WINDOWS

  // then do some more PHP5 thingys
  ...
?>

The PHP4 interpreter will inherit the CGI environment, thus allowing to run as if it was the main script itself. With some cleaning up of that environment (regex filter ALL the variables) it doesn't have to be much of a security concern either. (But you didn't bother to update the code in the first place, so.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.