Shane E. Bryan
Shane E. Bryan

Reputation: 109

Running a second PHP script while keeping the client on same page

I'm creating a app that requires me to run a second php script while the first script is still running.

I'm new to php programing so I'm sure there's a simple function I can use that I'm just not aware of.

Looking forward to any help...

Shane

Upvotes: 0

Views: 174

Answers (2)

alairock
alairock

Reputation: 1934

This will actually require us to use some Javascript for an ajax call to execute our PHP and return it's data.

I prefer Jquery, which will look similar to this:

function callPHP(){           
     $.post('./filetocall.php', {variableid: 'id'}, function (response) {
                        $("#div_for_return_data").val(response);
                });
}

filetocall.php can look like anything. It's output will populate the #div_for_return_data

eg:

<?php echo $_GET['variableid']; ?>

Then just call the Jquery function from anywhere.

Upvotes: 0

Paul
Paul

Reputation: 141829

Since you are new to PHP I'm guessing you're looking for the include/require (and include_once/require_once) language constructs which will execute another PHP script as if it is part of the current script.

Otherwise if you want it to run as a separate process look into exec, shell_exec, or backticks. If you need the other PHP script to run as a background process make sure to redirect stdout somewhere (a file or maybe /dev/null if you don't need it) so that your currently executing script doesn't have to wait for it to finish to continue executing.

Upvotes: 1

Related Questions