C++ and Command Line PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    C++ and Command Line PHP

    I want to run PHP scripts from my C++ program.
    I can run "php -n my_script.php" but I have 2 problems:

    1. From my C++ program I want to pass to PHP script a data structure (a
    C++ map). I think these solutions:
    a. Save from C++ program a temp file and load from PHP script
    b. PHP script stdin passed from my C++ program (I dont know how)
    c. Link with php5ts.dll (or .so) and pass the data (is it possible?)

    2. When PHP script finished, I want the stdout passed to a C++ string of
    my program and not to write in console.


    Can you suggest anything?


    sorry for my bad english and THANKS
  • Joachim Weiß

    #2
    Re: C++ and Command Line PHP

    <- Chameleon -> schrieb:[color=blue]
    > I want to run PHP scripts from my C++ program.
    > I can run "php -n my_script.php" but I have 2 problems:
    >[/color]


    how about sth like this:
    2 cplusprogs and a php file make the world.

    I hope it helps

    Jo

    example:

    hello.cc:
    #include <iostream>
    using namespace std;


    int main(int argc,char **argP) {
    cout << "Hello ";
    return(0);

    }

    world.php:
    #!/opt/lampp/bin/php -q
    <?php

    if(!defined("ST DIN")) {
    define("STDIN", fopen('php://stdin','r'));
    }

    if(!defined("ST DOUT")) {
    define("STDOUT" , fopen('php://stdout','w'));
    }

    $in =fread(STDIN,10 24);

    $out="$in World";

    fwrite(STDOUT,$ out);
    fflush(STDOUT);
    die(0);
    ?>


    endWord.cc:
    #include <iostream>
    using namespace std;

    int main(int argc,char **argv) {
    char in[1024];

    cin.get(in,1023 );

    cout << in << "!\n";

    return(0);
    }


    ../hello | ./world.php | ./endWorld
    prints:
    Hello World!

    Comment

    Working...