Ok i wanted to create a crawler with my PHP script. Certain parts of my crawler requires real fast manipulation of strings thats why i have decided to use a C/C++ program to assist my PHP script for that particular job. The following is my code:
$op=exec('main $a $b');
echo $op;
main is the executable file generated using my C file main.c i.e main.exe. in the above operation i just made a simple C program which accepts 2 values from PHP and returns the sum of the two values. the following is how my C program in looking like
#include< stdio.h >
#include< stdlib.h >
int main(int argc, char *argv[])
{
int i=add(atoi(argv[1]),atoi(argv[2]));
printf("%d\n",i);
return 0;
}
int add(int a, int b)
{
int c;
c=a+b;
return c;
}
i tried to execute the program via the CMD main 1 1 and it returned 2....it worked! when i entered them in the php script like this,
$a=1;
$b=1;
$op=exec('main $a $b');
echo $op;
it didn't work as expected so any ideas, suggestions or anything else i need to do on my code. I would be great if you could show me an example. THANKS IN ADVANCE!!!