Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute and output PHP on a C based web-server - Stuck!
    primarykey
    data
    text
    <p>I'm doing a bit of coursework for university and I'm completely baffled. Basically I've made a basic web server (which uses sockets) in C. I've now got to make it so that any .php file, is run through the php compiler and output.</p> <p>The problem I'm having is that I've tried using system() and execlp() (the latter was recommended by our lecturer) and cant find out how to get it to show on the page instead of the terminal.</p> <p>Here's an extract showing the code I've currently got. Please excuse all the comments...as you can see I've been trying all sorts to get it to work!</p> <p>CODE:</p> <pre><code>if(strncmp(resource, ".php", 4)==1) { //cout &lt;&lt; "test"; </code></pre> <p>int php;</p> <pre><code> int phppipefds[2], phppid; char phpc; pipe(phppipefds); phppid = fork(); if(phppid == 0) { // child will read pipe close(0); // close stdin dup2(phppipefds[0],0); // read pipe on stdin close(phppipefds[1]); // we dont need to write pipe execlp("/Applications/MAMP/bin/php5/bin/php", "php", httppath, NULL); cerr &lt;&lt; "exec failed\n"; exit(1); } // parent, if we redirect stdout printf will send down pipe close(1); dup2(phppipefds[1],1); // write pipe on stdout close(phppipefds[1]); // dont need 2 write descriptors close(phppipefds[0]); // we dont need to read pipe cout &lt;&lt; "words \ngoing \ndown \npipe \nbeing \nsorted\n"; close(1); // must close pipe or sort will hang wait(0); //php = system("/Applications/MAMP/bin/php5/bin/php /Users/rickymills/webserver/pages/test.php"); //strcat(resp, ); //strcat(resp, php); } </code></pre> <p>The last few lines are where I've been trying all sorts to get this thing to work.</p> <p>The actual part where everything is dumped to the browser windows is just below the above code:</p> <pre><code> write(connsock, resp, rd); exit(1); } </code></pre> <p>Does anyone have any idea how I can get this to the browser window? I would have thought the best way would be to get the php output into a variable, and combine it with 'resp' before the connsock write out, is this correct?</p> <p>Thanks for your time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload