
Originally Posted by
poymode
Hi IM back with a new problem, how can you let ur webserver support PHP and MYSQL?
Hi,
If you're making your own server, I really suggest that you just concentrate on the web server so that it will be less complicated. 
Anyway, there are many ways to let your server support PHP. A very easy way is to let your server pipe its output to PHP:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char **argv)
{
pid_t id;
int count;
int fildes[2];
char php_code[] = "<?php echo \"Hello world!\n\"; ?>";
pipe(fildes);
if ((id = fork()) == 0) {
/* we are in the child */
close(0); /* close stdin */
dup(fildes[0]); /* put read end of pipe into stdin index */
close(fildes[1]); /* close "write" end of pipe */
if (execlp("php-cgi", NULL) < 0) {
printf("execl failed\n");
exit(1);
}
} else {
/* we are in the parent */
/* close "read" end of pipe */
close(fildes[0]);
/* send code to PHP interpreter */
write(fildes[1], php_code, strlen(php_code));
/* close write end to tell sort we are done */
close(fildes[1]);
id = wait(NULL); /* wait for child */
}
return(0);
}
Here's the output:
Code:
simoncpu@localhost:/tmp$ gcc -o pipe-sample pipe-sample.c
simoncpu@localhost:/tmp$ ./pipe-sample
Content-type: text/html
Hello world!
You can also bind PHP to an address and port, and communicate to it via sockets but it's a bit complicated. Just google for "socket programming" for more info.
Please note that the above code works for PHP-CGI only. Enjoy!