Calling C++ program from PHP on linux

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.

  <title>PHP Test</title>
echo exec('ls -lrt');
echo exec("testprog");


#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] << ' ';

Try exec(“./testprog”)

It works!
Why setting the currrent path “.” by the environment variable PATH does not work?
echo $PATH

The reason is that the “exec” shell is not your login shell and doesn’t respect your .profile .

In general it’s better to use absolute paths rather than relying on the current dir, which is not necessary the script directory.

$path = dirname(__FIILE__) . "/testprog";