0

OK look:

What I want to do is the following (this is an example):

  1. $output = require( "script_execution.php" );
  2. echo str_replace( "hello", "bye", $output );

The solution I have:

(script_execution.php)

<?php
   echo "hello world....";
?>

(solution.php)

<?php

  ob_start();
  require( "script_execution.php" );
  $output = ob_get_contents();
  ob_end_clean();
  echo $output; // WOW!!! but.......................

?>

(output)

bye world....

Here is the problem: That solution works fine but, ¿What happens if "script_execution.php" has an (exit;) ??? The final output will be wrong because before the third instruction all execution running is stopped.

¿What can I do to get the final output of "script_execution.php" without exit my script (solution.php)? Because as you know, the final output of script_execution.php (independent of the exit; instruction) is:

hello world....

Thanks! (maybe using threads??)

CRISHK Corporation
  • 2,948
  • 6
  • 37
  • 52

1 Answers1

2

If you evaluate the script with include or require, and it calls exit(), your script will terminate.

You have two options that I see:

  1. Using a shutdown handler with register_shutdown_function() to run when exit() is called, then capture the output buffer within the function and print it.

  2. Execute only script_execution.php by making an HTTP request to your server, with something similar to:

    $output = file_get_contents( 'http://www.yoursite.com/script_execution.php');
    
nickb
  • 59,313
  • 13
  • 108
  • 143