calling C++ program from PHP on linux

Discussion in 'PHP' started by albertkao, May 5, 2010.

  1. #1
    I want to call a C++ program from PHP with apache server on Fedora 12 linux.
    I see the output of exec('ls -lrt') but not exec("testprog").
    testprog is put in the same directory of the test php program.
    Please help.
    The following are my php and cpp test programs.
    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>
    <?php
    echo exec('ls -lrt');
    echo exec("testprog");
    ?>
     </body>
    </html>
    
    Code (markup):
    testprog.cpp
    #include <iostream>
    #include <algorithm>
    
    int main() {
      int array[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30 };
      int elements = sizeof(array) / sizeof(array[0]); 
      std::sort(array, array + elements);
      for (int i = 0; i < elements; ++i) 
         std::cout << array[i] << ' ';
    }
    Code (markup):

     
    albertkao, May 5, 2010 IP