tags:

views:

49

answers:

4

Is it possible to launch a php file from a other php file? I know that i can include a file but i don't mean this.

Small example: i have a script which displays something from the database and a other script which get the latest data from a other site and update the database.

When i include the update file, the first script will request the data from the server but i want to make it parallel so that only the update script request from server

A: 

Yes, you need CURL (or any other HTTP library) to "run" a php file from another as you described in your scenario.

So, in your case:

  1. CLIENT will run a REQUEST to SERVER1 (a.php)
  2. SERVER1's a.php, will use CLIENT REQUEST to perform a remote PHP file in SERVER2 (b.php)
  3. SERVER2's b.php will process SERVER1's REQUEST and place an appropriate response
  4. SERVER1's a.php will receive SERVER2's b.php RESPONSE, parse it, and send appropriate response to CLIENT.

Hope it clarifies something to you.

Pablo Santa Cruz
A: 

Yes, it is possible.

Vlad Lazarenko
+4  A: 

Yes, and you can use include provided fopen wrappers are turned on.

include("http://otherserv.com/path/to/script.php");

If you don't care about the reponse from the other server, you can do

get_headers("http://otherserv.com/path/to/script.php");

This will complete much faster if the remote script takes time to process.

Byron Whitlock
A: 

you should look at exec http://au.php.net/manual/en/book.exec.php

deepsat
Can you be more specific? This seems very wrong to me.
Chouchenos
why is it wrong? please read the documentation!
deepsat
exec is highly discouraged for various security reasons. Byron has the most appropriate answer.
Andrew Sledge
@Andrew: my bad! thanks!
deepsat