I’m writing an application that sends requests to the PHP CLI. However, as i try to run the application, php complains it can’t find the script to run.
Here’s the relevant code:
char *params[] = {
"/usr/bin/php",
"-f /var/www/test/php/tracker/gps-upload-sh.php",
imei,
rmc,
(char *) 0
};
signal(SIGCHLD, SIG_IGN);
pid_t pID = fork();
if (pID == 0) {
if(execv("/usr/bin/php", params) == -1) {
perror("Failed to call php.");
_exit(1);
}
_exit(0);
}
Output:
$ ./socket
Could not open input file: /var/www/test/php/tracker/gps-upload-sh.php
^C
File:
$ ls -l /var/www/test/php/tracker/gps-upload-sh.php
-rwxr-xr-x 1 onik onik 6707 2012-03-09 16:00 /var/www/test/php/tracker/gps-upload-sh.php
Run directly (where REQUIRED_PARAMS are the same as the ones passed from the execv):
$ php -f /var/www/test/php/tracker/gps-upload-sh.php [REQUIRED_PARAMS]
OK
What to do?
Try separating the
-fand the path into separate parameters:(This is what your shell does with you put a space between the two.)
Alternatively, remove the space between
-fand the path: