Execute and output PHP on a C based web-server - Stuck! -


I am doing some research for the university and I am completely amazed, in fact I have a basic web server in C ( Which uses sockets). I have now got to create it so that any .php file can be run via PHP Compiler and output.

The problem I feel is that I tried to use the system () and execlp (the latter was suggested by our lecturer) and do not know how to show it on the page instead of the terminal.

This is an exclamation showing the current code. Please excuse all comments ... As you can see that I am trying all kinds of work to do it!

CODE:

  if (strncmp (resource, ".php", 4) == 1) {// cout & lt; & Lt; "testing";  

int php;

  int phppipefds [2], phppid; Four phpc; Pipes (phppipefds); Phppid = fork (); If (phppid == 0) {// children will read the pipe closed (0); // Close studin duplex 2 (ppppfds [0], 0); // reading pipe on studin clause (ppppfdf [1]); // We do not need to write pipe execlp ("/ application / mamp / bin / php5 / bin / php", "php", httppath, null); Serie Lieutenant; & Lt; "Execution failed \ n"; Exit (1); } // Parents, if we redirect stdout printf, then send the pipe off (1); Dup2 (phppipefds [1], 1); // Write pipes on standout off (phppipefds [1]); // Two characters do not need to be written (phppipefds [0]); // We do not need to read the pipe cat & lt; & Lt; "The word \ ngoing \ ndown \ npipe \ n is running \ n \ n"; Pass (1); // should hang off the pipes or wait (0); // php = system ("/ application / mmp / bin / php5 / bin / php / users / finite / webers / page / test. Php"); // rotate (resp); // strcat (resp, php); }  

The last few lines are where I am trying all kinds of work to do this work.

The actual part where everything is thrown in the browser window is just below the code above:

  write (console, resp, RD); Exit (1); }  

Does anybody have any idea how can I get it into a browser window? I would have thought that the best method would be to bring the PHP output into one variable, and it must be added with 'resp' before writing the samote, is it correct?

Thank you for your time. Try using instead of

system () or execlp () .

The popen () function opens a process by opening a pipe, focusing, and shell. This should allow you to redirect the PHP output to your program instead of the terminal.

  char buf [BUFSIZ]; File * FP; If you read (/ fp = popen ("/ bin / php -f /webserver/pages/test.php", "r")) = null) / / from PHP command output * / while (fgets (buf, bufsiz) , Fp)! = NULL) {/ * Perform desired output process from PHP / / ...} (zero) Pclus (PTR); } Fclose (fpose);  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -