0

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

3
  • exec('php path/to/the/script'); Commented Feb 28, 2012 at 5:43
  • mywiki.wooledge.org/XyProblem Commented Feb 28, 2012 at 5:43
  • Thanks @k102 I think I'll use that. I also asked a couple questions on PaulP.R.O Answer that I could use some help on... Commented Feb 28, 2012 at 6:10

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

absolutely what i think he wants.
I think the exec operator will work great, but if I need to pass var. how would I do that? Also will the first script continue or will it wait for a response?
@ShaneE.Bryan Are you familiar with a linux shell (and running PHP ON Linux)? exec takes in a command if you want to pass arguments to that command you can just append them to the command string separated by whitespace like '/usr/bin/php ' . $filename to run a php script whose name is stored in the variable $filename (If your php interpreter is located in /usr/bin/php). You probably also want to escape your arguments with escapeshellarg. The script will wait for a response unless you redirect stdout somewhere like: exec('/usr/bin/php ' . escapeshellarg($filename) . ' > /dev/null');
So if I have multiple var. i would code it like this <code> exec('/usr/bin/php . escapeshellarg($filename?var=$var&var2=$var2) . ' > /dev/null'); </code>
Also if I run <?php phpinfo() ?> which field would include the root dir for php?
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.