I have a new question for the web server, when I send it a new php web page request (in the browser, typing:
http://localhost:8080/test/index.php)
In the output generated from the code above, the code path for the php request does a popen() followed by load(), instead
of what it did for an html request, which was an fopen() followed by load(), and this seems to fail because in my load function,
the same code that I used to see how much allocated space I needed for the html file request does not work for the php request, since
it was opened with popen() rather than fopen(), and I know popen() forks and execs a process rather than just opens a file.
I am familiar with forking and execing processes, but I've never used popen() before.
It seems to think that the content space needed is zero.
This is the output. I can provide the php code I downloaded, if that would be needed.
In the load() code, for the html file, I had gotten the content size needed this way, but I read when I did a web search
that this was a "coding kluge".
Code:
fseek (file , 0 , SEEK_END);
filesize = ftell (file);
rewind (file);
So I tried this way:
Code:
if (fstat(fileno(file), &sb) == -1)
{
perror("stat");
exit(EXIT_FAILURE);
}
printf("File size from fstat(): %lld bytes\n", (unsigned long long) sb.st_size);
Yet you will see in the output below, that fstat() says my file size needed is zero bytes.
The kluge code file size says -1 bytes are needed.
karen webserverToPhysComp $ ./server public
Using /home/karen/dev/cs410Projects2and3_2015to2016/webserverToPhysComp/public for server's root
Listening on port 8080
checking for client connections
starting infinite loop to look for client browser requests
checking if client has connected
calling accept(): extracts the first connection request on the queue of pending connections for the listening socket (server), sockfd, creates a new connected socket, and returns a new file descriptor referring to that socket (client)
client: addr = 16777343
client has connected - check for request
request: reading message
message from client = GET /test/index.php HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
length = 405
GET /test/index.php HTTP/1.1
parsing request-line from client: line = GET /test/index.php HTTP/1.1
parsing line = GET /test/index.php HTTP/1.1
parsing for the GET method
should be pointing to request-target part of line = /test/index.php HTTP/1.1
start of abs_path = /
pathChars = /test/index.php countAbsPath = 15
len of abs_path = 0 len of pathChars = 15
parse: abs_path = /test/index.php
no query found
parse: query =
are we pointing at HTTP's and it's version? HTTP/1.1
and HTTP/1.1
HTTP/1.1 found - correct version for now
abs_path returned from parse = /test/index.php
query returned from parse =
calling lookup on path = /home/karen/dev/cs410Projects2and3_2015to2016/webserverToPhysComp/public/test/index.php
lookup on path = /home/karen/dev/cs410Projects2and3_2015to2016/webserverToPhysComp/public/test/index.php
pathToPeriod = (null) lastPeriodInPath = php
type = text/x-php
interpret being called with path = /home/karen/dev/cs410Projects2and3_2015to2016/webserverToPhysComp/public/test/index.php and query =
interpret: calling popen() on command = QUERY_STRING="" REDIRECT_STATUS=200 SCRIPT_FILENAME="/home/karen/dev/cs410Projects2and3_2015to2016/webserverToPhysComp/public/test/index.php" php-cgi
interpret: calling load() file popened = 5
load a file into memory file = 5
File size from fstat(): 0 bytes
file size from fseek(): -1 bytes
file size less than READMEGABYTEFROMFILE = 0
numBuffers = 1, numBytesToRead = filesize = 0
*content = 0 before calling realloc