How to make php script run another php script

php

Solution

You can try to start another PHP process in the background via the shell. It is somewhat of a hack, won't work on all operating systems, and might not work on shared web servers.

file1.php

<?php
$somearg = escapeshellarg('blah');
exec("php file2.php $somearg > /dev/null &");   

file2.php

<?php
//do some stuff that will take a while
//$argv should contain 'blah', and also it seems the name of the php file
//this script will continue to run. You might want to set max_execution_time to a sensible value.

Problem

I'm trying to do exactly the same thing as in my previous Python question, but in PHP. See my previous (answered) question PHP script from previous question does something and then runs another PHP script on the same server, does something and then quits (while second script still continues its work). How do I achieve this? Please note that PHP script is also a web page at the same time (so maybe we can use it like in previous question where answer to my question was snippet that made python just open url instead of running subprocess... although I don't have a clue if that's useful information, maybe it's different in PHP, I'm not too experienced in PHP)... and that I want to make each scripts independent - so if first php script will finish I would like second php script to continue working even though first one ended. What do you think is most elegant way to do this? Would echoing iframe work or should I do this differently?

Original source

Related problems