• [^] # Re: Optimisations:

    Posté par . En réponse au journal Mon serveur Web. Évalué à 10.

    On peut même se passer du content-length en HTTP/1.0, vu que pas de keep-alived. (Sans keep-alived, la fin du document c'est quand la connexion est fermée).

    Sinon en PHP, 0 fork:


    #!/usr/bin/php5
    HTTP/1.0 403 Forbidden
    Date: <?php echo date(DATE_RFC822)."\r\n"; ?>
    Server: Apache
    Content-Type: text/html

    <?php readfile('/var/www/blacklisted/index.html'); ?>


    Ou en C:

    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>

    #define STATUS "HTTP/1.0 403 Forbidden"
    #define SERVER "Apache"
    #define CONTENT_TYPE "text/html"

    #define PAGE_FILE "/var/www/blacklisted/index.html"

    int main(int argc, char *argv[])
    {
    char date[50];
    time_t t;
    struct tm *tmp;
    FILE *fp;
    char line[1024];

    t = time(NULL);
    tmp = localtime(&t);
    strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", tmp);

    printf("%s\r\n", STATUS);
    printf("Date: %s\r\n", date);
    printf("Server: %s\r\n", SERVER);
    printf("Content-Type: %s\r\n", CONTENT_TYPE);
    printf("\r\n");

    if ((fp = fopen(PAGE_FILE, "r")) == NULL) {
    perror("Could not read file");
    return 1;
    }

    while (fgets(line, 1024, fp) != NULL) {
    printf("%s", line);
    }

    fclose(fp);

    return 0;
    }