how to invoke external php script ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • konsu

    #1

    how to invoke external php script ?

    hello,

    when a web request comes to my index.php, i would like index.php to execute
    a php script stored in an external file and capture the external script's
    output to a variable.

    i am doing this because the external script can read the database and can
    emit xml that i want to use. index.php (or whatever) wants to grab this xml
    and pass it through an xslt.

    i know that if the external php script had a function declared, and the
    function returned a string value with the xml contents, then i could use
    "require" or a similar construct and call the function. the question that i
    am trying to answer is what to do if the external script uses echo() to
    output the results? how to capture its output during request processing?
    besides, i do not like spawning another process for that and piping to it.
    it might not scale well. ;-)

    please help.
    thanks
    konstantin


  • Jamie Davison

    #2
    Re: how to invoke external php script ?



    Use the -q directive to suppress headers

    In index.php:
    $stdout_var = shell_exec(/usr/local/bin/php -q /path/to/the/php/file.php);

    Make sure file.php is chmod 755 or thereof

    Check the path to php (could be "sbin")

    You could write $stdout_var to file or do whatever from here.





    On 2/25/05 1:25 PM, in article e-6dnXZO8pk98ILfR Vn-iw@kallback.com, "konsu"
    <konsu@hotmail. com> wrote:
    [color=blue]
    > hello,
    >
    > when a web request comes to my index.php, i would like index.php to execute
    > a php script stored in an external file and capture the external script's
    > output to a variable.
    >
    > i am doing this because the external script can read the database and can
    > emit xml that i want to use. index.php (or whatever) wants to grab this xml
    > and pass it through an xslt.
    >
    > i know that if the external php script had a function declared, and the
    > function returned a string value with the xml contents, then i could use
    > "require" or a similar construct and call the function. the question that i
    > am trying to answer is what to do if the external script uses echo() to
    > output the results? how to capture its output during request processing?
    > besides, i do not like spawning another process for that and piping to it.
    > it might not scale well. ;-)
    >
    > please help.
    > thanks
    > konstantin
    >
    >[/color]

    Comment

    • Google Mike

      #3
      Re: how to invoke external php script ?

      Another route is:

      $sResponse = `php -q -d max_execution_t ime=60000
      /path/to/php/file.php`;

      In this example, I also add the "-d max_execution_t ime=60000" so that
      your external script has a longer timeout time, in case you need that.

      Note the backticks (`) in the code above -- these are not single
      quotes.

      I also don't do a direct path to PHP. If your $PATH already contains
      the PHP bin path, then you might not need it.

      Also, on my system, PHP is reached with /usr/bin/php instead of
      /usr/local/bin/php. (I have RH9 Linux.)

      Comment

      • NC

        #4
        Re: how to invoke external php script ?

        konsu wrote:[color=blue]
        >
        > when a web request comes to my index.php, i would like index.php
        > to execute a php script stored in an external file and capture
        > the external script's output to a variable.[/color]

        Is that script located on your system or somewhere else? If it
        is local, (i.e., resides on your system), you can simply do
        soomething like this:

        $capture = file_get_conten ts('http://localhost/script.php');

        If the external script is remote, you can do

        $capture = file_get_conten ts('http://www.example.com/script.php');

        Cheers,
        NC

        Comment

        Working...