7

What I'm trying to work out how to do is this: I've got a php file let's call trigger.php that runs some php code that sets off another php file we'll call backgroundProcess.php to start processing.

Although trigger.php needs to ignore what happens to backgroundProcess.php, it just has to start it processing and it will stop while backgroundProcess.php keeps going.

edit1

I'm running this on Windows Wampserver 2.1 So this has to be a windows command.

edit2

Solved it with the following command, thanks to jakenoble's suggestions:

exec("C:\wamp\bin\php\phpVERSION_NUMBER\php.exe -f C:\wamp\www\path\to\backgroundProcess.php");

1 Answer 1

7

You can use exec() and add an & to the end of the call, plus an output stream:

In trigger.php

exec("php backgroundProcess.php > /dev/null &");

You can find out more here http://php.net/manual/en/function.exec.php

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

6 Comments

This doesn't work. I'm using WAMPSERVER 2.1 so perhaps that's the issue? Is there a way to work around this?
Unless I'm doing something else wrong.... I've got both php files in the same folder and am running the the above command.
It won't work, Windows probably doesn't know where php is installed and therefore cannot execute it. Try launching a command window and executing the script there, then take that code and use it in exec(). I don't use Windows so can't really help much more. You might want to revise your question as this changes everything.
Solved! :) With the following command: exec("C:\wamp\bin\php\phpVERSION_NUMBER\php.exe -f C:\wamp\www\path\to\backgroundProcess.php");
Unix or windows alike, this assumes the php location to be in the PATH variable (%PATH% for Windows and $PATH for unix). In unix it generally is, while in Windows it generally isn't. The alternative to adding the php directory to the path environment variable is inserting a full path. This is possible in windows and unix, but it won't be portable at all.
|

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.