BASIC Counter Application

A Basic FastCGI application

An example in powerbasic

FUNCTION WINMAIN()

  DIM sReply AS STRING 
  DIM FCGXReq AS FCGX_REQUEST '// FCGX Structure
                                
'// Intialize Databases etc here               

    '// Create the STDIN/STDOUT/STDERR buffers, Connect with the Web Server via FCGI Library
    CALL FCGX_InitRequest(FCGXReq, 0, 0)


    DO '// Process next HTTP Request

      '// Execution blocked here until an HTTP request arrives
      IF FCGX_Accept_r(FCGXReq) < 0 THEN EXIT LOOP '// SIGTERM/Error recieved - jump out and cleanup


      '// The reply must begin with a valid HTTP header
      sReply = "Content-Type: text/html"+$CRLF+$CRLF             
      sReply = sReply + "ReqCount=" + STR$(FCGXReq.ReqCount)

      '// Add the Reply string to the STDOUT buffer
      IF FCGX_PutStr( STRPTR(sReply), LEN(sReply), FCGXReq.pOut ) < 0 THEN EXIT LOOP '// Error Occured

    LOOP '// STDOUT is sent when FCGX_Accept_r is called again

'// Close Databases etc here

END FUNCTION
Comments