0

Currently I have 2 PHP files. 1 is the user interface and another fetches data from the backend and inserts into the database.

Currently if I use the following in the UI php:

<html>
    <body>
        <form action = "test.php" name="form" method="post">
            <input type="text" name="text_box" size="50"/>
            <input type="submit" id="search-submit" value="submit"/>
        </form>
    </body>
</html>

Upon clicking submit it goes to the test.php. If it possible to execute test.php in the background while remaining on the UI php?

Some of the previous posts talk about using ajax etc which I am not sure how to implement. Possible to do this in php?

7
  • 1
    instead of calling another file for action. You can keep the same file as the action. Commented Feb 4, 2013 at 6:47
  • 1
    I upvoted your comment, but Ajax would be the more modern/user-friendly way. Commented Feb 4, 2013 at 6:49
  • @Lenin But I need to call the another file to execute the fetching if data. You mean put all the code together in 1 php file? Commented Feb 4, 2013 at 6:51
  • 2
    you could use if(isset($_POST['submit'])) and than put all php code on same page Commented Feb 4, 2013 at 6:55
  • @IanO.S. Yes, that will solve my issue. Thanks :) Commented Feb 4, 2013 at 7:03

1 Answer 1

1

In test.php you can use the exec function and call whatever php file you want using php by command line:

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

Just notice that the session that it will have is not the same as what you have on the browser, and it can be tricky to send parameters to the command line instance that is being initiated, take a look here.

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

4 Comments

Would normal script timeout be in effect, since this would be a CLI call? I honestly don't know.
We just have timeout issues with server/client architecture, using CLI call you can do whatever you want.
Plus most hosts don't allow exec, etc., for obvious reasons.
What I saw is that apache user doesn't have permission to execute anything else php CLI and other really simple and no-harm commands.

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.