Server push applications using FastCGI

Mark Brown (mbrown@OpenMarket.com)
Thu, 25 Jul 1996 18:53:11 -0400

Message-Id: <199607252253.SAA25484@breckenridge.openmarket.com>
To: fastcgi-developers@OpenMarket.com
Subject: Server push applications using FastCGI
Date: Thu, 25 Jul 1996 18:53:11 -0400
From: Mark Brown <mbrown@OpenMarket.com>


Ron Newman <rnewman@nfic.com> writes:

    A non-parse-header (nph) CGI program can send output
    intermittently to the client; the web server does not wait for the
    nph CGI program to return before forwarding the CGI standard
    output to the client.

    Is there any way to get equivalent functionality in FastCGI?  When
    a FastCGI program writes to stdout, is all of the output buffered
    until the next call to FCGI_Finish (or FCGI_Accept), or does the
    web server send the output to the client as soon as it receives
    the data?

A Web server that implements FastCGI sends application data to the
client as long as there is any data to send; the data doesn't linger
indefinitely in the server's buffer.  (Actually, the spec is silent on
the issue, because I didn't realize it *was* an issue.  The Open
Market server treats NPH and non-NPH CGI scripts the same with respect
to buffering.  As a result of your query the spec will improve;
thanks!)

I attach a tiny server-push FastCGI application that I just ran on the
Open Market server, to make sure.  I'd appreciate it if somebody using
Apache would try this example on Apache, and somebody using NCSA would
try it on NCSA, to verify that those FastCGI modules are working
correctly for server push applications.

    --mark

* * * * *

/* 
 * push.c --
 *
 *	FastCGI example server-push program using fcgi_stdio library
 *
 *
 * Copyright (c) 1996 Open Market, Inc.
 *
 * See the file "LICENSE.TERMS" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include "fcgi_stdio.h"
#include <unistd.h>
#include <stdlib.h>

void main(void)
{
    int count = 0;
    while(FCGI_Accept() >= 0) {
        ++count;
        printf("Content-type: multipart/x-mixed-replace;"
                       "boundary=ThisRandomString\r\n"
               "\r\n");
        printf("--ThisRandomString\r\n"
               "Content-type: text/plain\r\n"
               "\r\n"
               "one (request %d)\n", count);
        fflush(stdout);
        sleep(5);
        printf("--ThisRandomString\r\n"
               "Content-type: text/plain\r\n"
               "\r\n"
               "two (request %d)\n", count);
        fflush(stdout);
        sleep(5);
        printf("--ThisRandomString\r\n"
               "Content-type: text/plain\r\n"
               "\r\n"
               "three (request %d)\n", count);
        printf("--ThisRandomString--\r\n");
    }
}

* * * * *