Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to execute php code in a sandbox from within php

Tags:

I want to execute a php-script from php that will use different constants and different versions of classes that are already defined.

Is there a sandbox php_module where i could just:

sandbox('script.php'); // run in a new php environment 

instead of

include('script.php'); // run in the same environment 

Or is proc_open() the only option?

PS: The script isn't accessible through the web, so fopen('http://host/script.php') is not an option.

like image 885
Bob Fanger Avatar asked Nov 27 '08 22:11

Bob Fanger


People also ask

Where should PHP codes be executed?

As a Windows user, though, you'll need to type the full path to the PHP executable to run a PHP script. The PHP executable is usually available at C:\php7\php.exe, so you can use it to execute the PHP file as shown in the following command. For Linux, you don't need to type the whole path to the PHP executable.

Can I run PHP inside HTML?

If you want to run your HTML files as PHP, you can tell the server to run your . html files as PHP files, but it's a much better idea to put your mixed PHP and HTML code into a file with the . php extension.


2 Answers

There is runkit, but you may find it simpler to just call the script over the command line (Use shell_exec), if you don't need any interaction between the master and child processes.

like image 161
troelskn Avatar answered Oct 01 '22 02:10

troelskn


The is a class on GitHub that may help, early stages but looks promising.

https://github.com/fregster/PHPSandbox

like image 44
Paul Avatar answered Oct 01 '22 02:10

Paul