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.

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

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:

  // do some PHP5 code here

  // then invoke the script parts for PHP4
  passthru("php4-cgi.exe .../script2.php4");

  // 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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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