function to execute another PHP script?
Posted: Sat Sep 16, 2006 1:42 pm
Is there a function to execute another PHP script out-of-process?
What I'm working on, is a framework for meta-programming in PHP. So a simple include or require won't do - I need to be able to execute a PHP script "outside" the current process ... in a separate PHP environment - so that, if the generated meta-program fails, the main program can capture the error.
I've tried the Apache-specific virtual() function - but this runs inside the current environment ... if the sub-script fails, the main script fails with it, and either way, the sub-script can access and overwrite variables in the main script.
I've also tried file_get_contents() with an URL to the sub-script, to get it's output - this works fine as such, except that I have no way to detect if an error occurred in the subscript, as this will simply generate an error-message as HTML inside the output, the way PHP normally does.
I've tried custom error-handling as well, using include/require with output-buffering to capture the output ... to no avail - too many types of errors can't be handled, and some of the errors that can't be handled then cause the subscript to output an error into the output-buffer, which is then never displayed, as the script terminates.
What I need, is basically a way to execute a PHP script, get it's output, and an error-status flag telling me if there were errors or not. Is there such a thing?
What I'm working on, is a framework for meta-programming in PHP. So a simple include or require won't do - I need to be able to execute a PHP script "outside" the current process ... in a separate PHP environment - so that, if the generated meta-program fails, the main program can capture the error.
I've tried the Apache-specific virtual() function - but this runs inside the current environment ... if the sub-script fails, the main script fails with it, and either way, the sub-script can access and overwrite variables in the main script.
I've also tried file_get_contents() with an URL to the sub-script, to get it's output - this works fine as such, except that I have no way to detect if an error occurred in the subscript, as this will simply generate an error-message as HTML inside the output, the way PHP normally does.
I've tried custom error-handling as well, using include/require with output-buffering to capture the output ... to no avail - too many types of errors can't be handled, and some of the errors that can't be handled then cause the subscript to output an error into the output-buffer, which is then never displayed, as the script terminates.
What I need, is basically a way to execute a PHP script, get it's output, and an error-status flag telling me if there were errors or not. Is there such a thing?