Results 1 to 40 of 123

Thread: VB6 FastCGI Server

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,892

    VB6 FastCGI Web App Server Framework

    NOW ON GITHUB - SOURCE CODE IN THIS THREAD WON'T BE UPDATED ANYMORE - GO TO GITHUB INSTEAD!! https://github.com/jpbro/VbFcgi

    This is a FastCGI web application server & framework written in VB6 for use with Nginx (and possibly other web server that support FastCGI).

    It handles FCGI_BEGIN_REQUEST, FCGI_END_REQUEST, FCGI_PARAMS, FCGI_STDIN, FCGI_STDOUT, and FCGI_STDERR records/communications quite nicely (currently being tested against the Nginx webserver). It can also launch itself as multiple processes to work against Nginx load-balancing features.



    Usage
    First you need to compile the latest source code (to vbFcgiHost.exe), then copy the compiled file and the vbRichClient5 DLLs (vbRichClient5.dll, DirectCOM.dll, and vb_cairo_sqlite.dll) to the same deployment folder.

    LATEST SOURCE CODE NOW ON GITHUB - SOURCE CODE IN THIS THREAD WON'T BE UPDATED ANYMORE - GO TO GITHUB INSTEAD!! https://github.com/jpbro/VbFcgi

    Next, you need a properly configured Nginx web server running, optionally with upstream load-balancing servers defined. For example, in nginx.conf, you might have something like this defined:

    Code:
    http {
       upstream backend {
             # Load-balancing across multiple FCGI listeners defined below
    	 server 127.0.0.1:9000;
    	 server 127.0.0.1:9001;
    	 server 127.0.0.1:9002;
    	 server 127.0.0.1:9003;
       }
    
       location ~ \.fcgi$ {
    			root html;
    			fastcgi_keep_conn on;
    			fastcgi_pass backend;  # This is where we've configured FCGI to be shipped out to our multiple listener process for load-balancing
    			fastcgi_index Default.aspx;
    			fastcgi_split_path_info ^(.*cgi)(/.*)$;
    			fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    			fastcgi_param PATH_INFO $fastcgi_path_info;
    			fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    			include fastcgi_params;
    	}
    
       # REST OF YOUR NGINX CONFIG
    }
    Next, start your vbFastCgi.exe process(es) from the command line (to match the load balancing configuration above you would use the following command line:
    vbfcgihost.exe /spawn 4 /host 127.0.0.1 /port 9000)

    You should see a browser page similar to the screenshot at the bottom of this page.

    That's it (other than coding your own responses)!




    Useful Resources
    Nginx Site: http://nginx.org/

    vbRichClient Site: http://www.vbrichclient.com

    FastCGI Spec: http://www.fastcgi.com/devkit/doc/fcgi-spec.html




    The following list of Gaps in Understanding and Known Issues will be updated as I go.

    Questions/Gaps in Understanding
    • The FastCGI protocol mentions that the web server can send SIGTERM to the FCGI server to ask it to close cleanly. Not sure how/if this is done in the Windows Nginx implementation since it handles it's FCGI communications over a TCP pipe and I've never received any message that I can identify as being related to SIGTERM.
    • Just bumped into SCGI as an alternative to FastCGI. Would it be better to use this protocol?
    • How should we handle the mixed "" "/" use in CGI parameters like DOCUMENT_ROOT on Windows? For example: DOCUMENT_ROOT = C:\Users\Jason\Downloads\nginx-1.7.9/html. Should I just convert all forward slashes to back slashes?
    • Answered by Olaf in Post #9 What does the CTcpServer.DataArrival FirstBufferAfterOverflow parameter mean? How should it be handled when TRUE?




    Known Issues
    • Not responding to all FCGI Roles. This is most likely a WONTFIX as I only need the RESPONDER role.
    • Not processing all FCGI record types (as of 0.0.5 only FCGI_DATA not supported, and I've never encountered it in the wild. The spec only says "FCGI_DATA is a second stream record type used to send additional data to the application." so I'm not sure when it applies, or what to do with the data in the stream.
    • FIXED IN 0.0.2 RELEASE Occasionally getting a "The connection was reset" error. Ngnix reports error: #5512: *263 upstream sent invalid FastCGI record type: 2 while reading upstream?





    NOW ON GITHUB - SOURCE CODE IN THIS THREAD WON'T BE UPDATED ANYMORE - GO TO GITHUB INSTEAD!! https://github.com/jpbro/VbFcgi

    Legacy Source Code vbFcgiHost.zip

    Version 0.0.8
    • Added support for parsing out HTTP query strings to key/value(s) pairs. Keys can have multiple values.
    • Added support for parsing out Cookies into Key/Value pairs.
    • Added htmlEscape function to ensure we're not sending special characters to the browser
    • Some tidy up, added missing variable type declarations on some functions.


    Version 0.0.7
    • Significant performance improvement by caching vbRichClient5.cCrypt object for re-use in DataArrival event (and elsewhere).


    Version 0.0.6
    • Changed the command line parameters (one fewer required, shorter switches)
    • When in SPAWNER mode, the process will monitor the LISTENER mode process for crashes, and restart crashed processes if necessary.
    • Mutex names are now instance specific based on the EXE path, allowing you to run multiple SPAWNER instances of vbFcgiHost.exe.
    • Additional comments and code cleanup


    Version 0.0.5
    Lots of changes - special thanks to Olaf for directing me to information about nginx load balancing across multiple FCGI listeners. This means we can avoid using threads, and just run multiple vbFcgiHost processes.
    • Renamed to vbFcgiHost (with a single vbFcgiHost.exe).
    • Now UI-less.
      To start listeners, use commandline vbfcgihost.exe /spawncount X /spawnstartport Y where X is the number of listener processes you want to create, and Y is the starting port number. For example, vbfcgihost.exe /spawncount 4 /spawnstartport 9000 will create 4 listener processes, one for each port from 9000 -9003.
      To stop listeners, use commandline: vbfcgihost.exe /stop
    • Now processing STDIN records
    • Better STDERR handling
    • Added new gc_MaxStdinInMemorySize configuration constant (bytes). STDIN streams at or below this size will reside in memory, STDIN streams above this size will be shuffled off to the filesystem.
    • Lots of code cleanup, new comments, and general improvements all around.


    Version 0.0.3
    • Added the gc_MaxResponseLoopSeconds configuration variable to allow you to tweak performance for multiple active requests (vs. relying on RC5 Timer granularity for short but many requests, or getting stuck on many but long requests).
    • General cleanup, and some error condition improvements
    • More comments!


    Version 0.0.2
    • Fixed bad value for FCGI_END_REQUEST constant (should have been 3, was 2)


    Version 0.0.1
    • So far we can process BEGIN, PARAMS, and STDIN requests from the web server, and respond with a basic web page listing all the received CGI parameters.
    • We can also handle Unicode transfer to the serve rin UTF-8 encoding.




    Browser Results Screenshot
    Name:  screenshot_appdemo.jpg
Views: 2860
Size:  46.6 KB

    Process Diagram
    You're only responsible for writing the stuff in BLUE. The startup/monitoring script/service is optional of course - you can just spawn the necessary process from a command line if you prefer Everything else is handled by the VBFCGI framework or third-party libraries/processes.

    Name:  diagram_processes.jpg
Views: 3332
Size:  45.9 KB
    Last edited by jpbro; Oct 14th, 2018 at 09:27 AM. Reason: NOW ON GITHUB - LATEST SOURCE UPDATES WILL NO LONGER BE POSTED HERE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width