Graviton
Graviton

Reputation: 83254

PHP: direct call another PHP web applications without going through the usual HTTP call

I have two PHP web applications. All of the apps are located on the same computer. Each application will run independently.

Now, can I do a direct API call from one PHP app to another? I don't want to go through either the webservice, or the usual HTTP call that involves HTML response. I want to call app A from app B, using direct method call, as if those two apps are the same application.

How to do this?

Upvotes: 0

Views: 883

Answers (2)

Otto Allmendinger
Otto Allmendinger

Reputation: 28268

Try using the system function.

<?php  system("php /path/to/other/php/script.php"); ?>

Upvotes: 1

Jeremy Smyth
Jeremy Smyth

Reputation: 23493

Usually, you'd use require or include to include the code from one PHP script in another.

If you hadn't done this before, or designed it in, you'll probably need to extract the functions from your script(s), place them in a central file, and include that in all scripts that need it (including, of course, the one they were originally in!). Remember that includeing a file in another causes its embedded HTML to be included too, so you'll typically include PHP files that have functions only, to achieve what you're asking.

Then you just call the function, as if it were written in the script in the first place :)

Upvotes: 3

Related Questions