Fastcgi programs run like a console program without IE6

 
Post new topic   Reply to topic    Aprelium Forum Index -> FastCGI/CGI
View previous topic :: View next topic  
Author Message
Spud2004
-


Joined: 12 Sep 2004
Posts: 21

PostPosted: Thu Dec 28, 2006 6:05 am    Post subject: Fastcgi programs run like a console program without IE6 Reply with quote

My executable cgi programs written in PowerBASIC work fine in cgi mode.
When I switch to fastcgi mode they run like a console application and
don't use the browser.
If I run a program like
STDOUT "Content-type: text/html" + CHR$(13, 10)
STDOUT "THIS IS LINE ONE" + "<BR>"

Get this message box from windows when running in fastcgi mode.
Do you want to run or save this file?
When run get this for output:
Content-type: text/html
THIS IS LINE ONE <BR>

Tried both the pipes and sockets option in the scripting configuration.
Using Windows XP SP2. Virtual path \cgi-bin.
Running server on local machine.
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Dec 28, 2006 11:49 am    Post subject: Re: Fastcgi programs run like a console program without IE6 Reply with quote

Spud2004,

A CGI program cannot work as a FastCGI one without modifying its source code and using a FastCGI library. We can send you a sample application using PowerBasic if you contact us on support@aprelium.com .
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Thu Dec 28, 2006 10:23 pm    Post subject: Reply with quote

The PB code was posted on the PB Internet forum. I recognized it immediately as my own, from a very long time ago - I was testing it with lighttpd at the time, but have never used it with Abyss. Perhaps it's time to try it out.

I was banned long ago from the PB forums for criticising the limitations of that compiler. The owner is very sensitive to criticism.

Spud2004, I may have additional PB fcgi code, if you're interested. BTW, the PB forum messed up your postings - the "REPLACE" lines in xmlClean() don't match what's in the original code.
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Dec 29, 2006 3:16 pm    Post subject: Reply with quote

chicks,

If possible, please post the additional code here.

BTW, If there are enough requests, we can start a section of the forum dedicated to PB users.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Fri Dec 29, 2006 6:34 pm    Post subject: Reply with quote

OK, here's an example that I was able to find right away. Will need to poke around a bit for other examples, as it's been a while. This example operates as a standalone fcgi service, waits for requests from an fcgi web server. Not fully tested, but worked a while ago when I was messing with lighttpd. The nice thing about doing it as an external service is that you can start and stop the service independently of the web server.

I can send you a binary .exe if you like, to test with your web server.

Code:

#COMPILE EXE "FCGIServer.exe"
#REGISTER ALL

#INCLUDE "win32api.inc"
#INCLUDE "fcgiapp.inc"

'-- Requires Don Dickinson's PB Service installer/handler code
'-- Available at http://www.greatwebdive.com

'-- *********************  NOTE ***********************************
'-- To install service:     fcgiserver -install
'-- To start fcgi server:   net start "fastcgi server"
'-- To stop  fcgi server:   net stop "fastcgi server"
'-- To remove service:      fcgiserver -uninstall

'-- Tcp port is hardcoded here (1027), but could be command line parm or from config file, etc.
'-- To test, you will need a FastCGI-capable web server, that can talk to remote fcgi's
'-- via tcp protocol.  I suggest using lighttpd, but Zeus and Apache are options, also.
'-- Set your web server to route "*.fcgi" requests to the ip address and port where this
'-- app is running, e.g. "127.0.0.1" and 1027

#INCLUDE "pb_srvc.bas"

$SERVICE_NAME = "FastCGI Server"
$SERVICE_DISPLAY_NAME = "PowerBasic FastCGI Server"

'-- Wrapper for FCGX_GetParam
FUNCTION GetParam(szParam AS ASCIIZ, envp AS FCGX_ParamArray) AS STRING
    LOCAL s AS DWORD
    LOCAL p AS ASCIIZ PTR

    s = FCGX_GetParam(szParam, envp)
    p = s
    IF p = %NULL THEN
        FUNCTION = ""
    ELSE
        FUNCTION = TRIM$(@p)
    END IF

END FUNCTION

'-- Print the environment strings
SUB PrintEnv(request AS FCGX_Request, szLabel AS ASCIIZ)

    LOCAL count AS LONG
    LOCAL p AS ASCIIZ PTR
    LOCAL envLen AS LONG

    CALL FCGX_FPrintF(request.pOut, "%s:<br><pre>", szlabel)

    DO
        p = request.@envp[count]
        IF p = %NULL THEN EXIT DO
        CALL FCGX_FPrintF(request.pOut, "%s<br>", @p)
        INCR count
    LOOP

    CALL FCGX_FPrintF(request.pOut, "</pre><p>")

END SUB

'-- Monitor service status, shut down FCGI library when service is stopped
FUNCTION MonitorThread ( BYVAL hServerThread AS LONG ) AS LONG

    DO
        SLEEP 1

        '-- This function tells us if the user stopped the service.
        IF pbsIsShutdown() THEN

            '-- Tell the FCGI library that we're shutting down
            CALL FCGX_ShutdownPending
            SLEEP 10

            '-- Exit this thread
            EXIT DO
        END IF
    LOOP

END FUNCTION

'-- Simple 404 handler
SUB Error_404(request AS FCGX_Request)

    '-- Write the error response
    CALL FCGX_FPrintF(request.pOut, _
            "Content-type: text/html" & $CRLF & _
            $CRLF & _
            "<html><title>Error</title><body><br/>" & _
            "<h1>404 Not found</h1><p>" & _
            "The requested resource does not exist on this server." & _
            "</body></html>" )

END SUB

'-- Simple echo handler
SUB Echo(request AS FCGX_Request)

    LOCAL ContentLength AS STRING
    LOCAL i AS LONG
    LOCAL ch AS LONG
    LOCAL length AS LONG
    STATIC count AS LONG
    LOCAL html AS STRING

    '-- Increment request counter
    INCR count

    '-- Write the response to the output stream
    CALL FCGX_FPrintF(request.pOut, _
            "Content-type: text/html" & $CRLF & _
            $CRLF & _
            "<html><title>FastCGI echo (fcgiapp version)</title><body><br/>" & _
            "<h1>PB FastCGI echo (fcgiapp version)</h1><br/>" & _
            "<pre>" & _
            "Request number: %ld, Process ID: %ld<br/>" & _
            "</pre>" & $NUL, _
            BYVAL count, _
            BYVAL GetCurrentProcessId() )

    '-- See if there's any content
    ContentLength = GetParam("CONTENT_LENGTH", request.envp)
    length = VAL(ContentLength)
    IF length <= 0 THEN
        CALL FCGX_PutS("No data from standard input.<br/><p>", request.pOut)
    ELSE
        CALL FCGX_PutS("Standard input:<br/><pre>", request.pOut)
        FOR i = 0 TO length-1
            ch = FCGX_GetChar(request.pIn)
            IF ch < 0 THEN
                CALL FCGX_PutS("Error: Not enough bytes received on standard input<br/>", request.pOut)
                EXIT FOR
            END IF
            CALL FCGX_PutChar(ch, request.pOut)
        NEXT i
        CALL FCGX_PutS("</pre><br/><p>", request.pOut)
    END IF

    '-- Echo the environment array
    PrintEnv request, "Request Environment"

    '-- Close html tags
    CALL FCGX_PutS("</body></html>", request.pOut)

END SUB

'-- Main thread.  Switch all requests to handler functions
FUNCTION ServerThread ( BYVAL foo AS LONG ) AS LONG

    LOCAL request AS FCGX_Request
    LOCAL fd AS LONG
    LOCAL ret AS LONG
    LOCAL scriptName AS STRING

    TRY
        '-- Initialize
        ret = FCGX_Init()

        '-- Get a socket descriptor for our tcp port
        fd = FCGX_OpenSocket ":1027", 5

        '-- Pass the socket descriptor to fcgi
        ret = FCGX_InitRequest( request, fd, 0& )

        '-- If we need to connect to a database, this is a good place to do it,
        '-- outside the main FCGI loop, so that it will only be called when we
        '-- start the service, not with each CGI request

        '-- Main FCGI loop - wait for requests, and switch them to handler functions
        DO WHILE FCGX_Accept_r( request ) >= 0&

            '-- Tune this for your web server - they don't pass all keys
            scriptName = LCASE$(GetParam("PATH_INFO", request.envp))
            IF scriptName = "" THEN
                scriptName = LCASE$(GetParam("SCRIPT_NAME", request.envp))
            END IF

            '-- Hand requests to handler functions
            SELECT CASE scriptName
                CASE "", "/", "/echo.fcgi"
                    Echo request
                CASE "/myfunction.fcgi"
                    '-- Anything you want can be handled in this switch statement
                    '--   Load and call functions in a DLL
                    '--   Call additional handler functions that you have added
                    '--   Etc.
                CASE ELSE
'                    Echo request
                    Error_404 request
            END SELECT

            CALL FCGX_Finish_r(request)
        LOOP
    CATCH
        '-- Any error handler code goes here
    FINALLY
        '-- Any cleanup code goes here - close database connections, etc.
    END TRY

END FUNCTION

'-- Main function
FUNCTION PBMAIN() AS LONG

    LOCAL hServerThread AS LONG
    LOCAL hMonitorThread AS LONG
    LOCAL foo AS LONG

    '-- Create main and monitor threads
    THREAD CREATE ServerThread(0) TO hServerThread
    THREAD CREATE MonitorThread(0) TO hMonitorThread

    '-- Start the service
    pbsInit 0, $SERVICE_NAME, $SERVICE_DISPLAY_NAME

    '-- Cleanup the thread handles
    THREAD CLOSE hMonitorThread TO foo
    THREAD CLOSE hServerThread TO foo

END FUNCTION

Back to top View user's profile Send private message
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Fri Dec 29, 2006 6:34 pm    Post subject: Reply with quote

Some old postings on the PB forums, thanks to webarchive.org:

http://web.archive.org/web/20050427093919/www.powerbasic.com/support/forums/Forum7/HTML/002642.html

http://web.archive.org/web/20050427094214/www.powerbasic.com/support/forums/Forum9/HTML/000927.html
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sat Dec 30, 2006 3:30 pm    Post subject: Reply with quote

chicks wrote:
OK, here's an example that I was able to find right away. Will need to poke around a bit for other examples, as it's been a while. This example operates as a standalone fcgi service, waits for requests from an fcgi web server. Not fully tested, but worked a while ago when I was messing with lighttpd. The nice thing about doing it as an external service is that you can start and stop the service independently of the web server.

I can send you a binary .exe if you like, to test with your web server.


Since we do not have the PB compiler it would be interesting to give the binary a try (please send it to support@aprelium.com). Actually we have done the tests with Perl, C/C++, and Python FastCGI servers. The language does not matter a lot since most of them rely on the same FCGI library. But the more tests we can make, the better it is for our QA.

By the way, connecting to an external FastCGI server is possible with version 2.4 (see the 2.4 Beta section for the download link - this version will be offcially released soon).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Sun Jan 14, 2007 4:45 am    Post subject: Reply with quote

Well, I've got to admit I'm impressed. Downloaded this tiny installer, had this thing up and running in 5 minutes. Another 5 minutes (after finding the "show console" and "configure" buttons, I had it talking to the PowerBASIC FastCGI service listed above. I'll install the SQLite version of the service tomorrow, which should provide a really nice, fast web service.
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Jan 14, 2007 6:53 pm    Post subject: Reply with quote

chicks,

Thank you for your feedback and for the compiled PB external FastCGI.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
ccs
-


Joined: 02 Apr 2005
Posts: 101

PostPosted: Mon Feb 19, 2007 5:05 pm    Post subject: Reply with quote

Quote:

BTW, If there are enough requests, we can start a section of the forum dedicated to PB users.

Just ran across this thread. Not sure how many PBer's are here, but that is my language of choice too. Abyss gets quite a bit of press on the PB site (lots from me too!). Not sure if this warrants a special forum here, but it should be noted that PB users are finding Abyss to be an excellent server for these executables and there is a growing interest in PB based web programming.

For anyone not familiar with PB, it is probably the most flexible compiler around. The power of C with the ease of Basic. Full access to all of Windows core functions, and produces the fastest, smallest, executables with no run-times or other dependencies necessary. It also makes creating DLLs extremely simple :)
Back to top View user's profile Send private message
Spud2004
-


Joined: 12 Sep 2004
Posts: 21

PostPosted: Mon Feb 19, 2007 5:07 pm    Post subject: Useful link to any new PB users Reply with quote

Here is a link if anyone using PB is having problems.

http://www.powerbasic.com/support/forums/Forum9/HTML/001188.html

Mike Doty


Last edited by Spud2004 on Mon Feb 19, 2007 6:01 pm; edited 1 time in total
Back to top View user's profile Send private message
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Mon Feb 19, 2007 5:57 pm    Post subject: Reply with quote

ccs wrote:

For anyone not familiar with PB, it is probably the most flexible compiler around. The power of C with the ease of Basic. Full access to all of Windows core functions, and produces the fastest, smallest, executables with no run-times or other dependencies necessary. It also makes creating DLLs extremely simple :)


None of which makes it an ideal Web programming language. It's a nice language for utilities and such, but PHP, Ruby and the like are far better choices if you're building a web site.

If you're fully invested in PB, though, the FastCGI interface is a nice addition. I wrote the PB fcgi examples for testing with lighttpd a couple years ago, it's nice to see they are being used now with this fine web server.
Back to top View user's profile Send private message
ccs
-


Joined: 02 Apr 2005
Posts: 101

PostPosted: Mon Feb 19, 2007 6:55 pm    Post subject: Reply with quote

Chuck,

While you are probably right for the most part, I have to say that I've returned to PB executables for my web programming over PHP for a number of reasons. The thing that tilted the scales though was the problems I kept running into with different versions. Things I wanted to do only worked in v5 but code I had huge investments in wouldn't run under 5. While the open source community is great, and I fully support it, there are advantages to commercial software. Abyss is an excellent example. In a market with "free" is king, Abyss out shines them all. I've had a number of issues (all early on) and the great people at Aprelium were right on top of it.

This is not to start an argument over what is the better choice. I think I know you well enough to know we agree that there are multiple good paths to the same end with software development. PHP is strong, solid, and widely popular. I've only skimmed the surface of RoR but it too seems like a very useful system. For many old VB programmers though (and those of us who have mainly use PB for a few decades now!) PB is a great choice since the learning curve is low, the executables are small, fast, and easy to use for web apps.

I'm just thankful that we're in a time when no one approach is 'required'. We're free to mix and match and use what works best for the project at hand :)

BTW, Thanks for all the great code samples you provided on the PB site over the years. I've started doing some very cool interactive (i.e. AJAX) stuff based on some examples you gave. I'd still be scratching my head if it weren't for those samples!

PS: neglected to add, for anyone interested: www.PowerBasic.com
Back to top View user's profile Send private message
roughbert
-


Joined: 05 Dec 2006
Posts: 4

PostPosted: Tue Feb 20, 2007 10:57 am    Post subject: PB forum? Reply with quote

Quote:
Not sure if this warrants a special forum here, but it should be noted that PB users are finding Abyss to be an excellent server..


If you say "not sure" because the other language forums have a vastly greater folowing than PB does, I would have to agree, although the PB compilers have a substantial following themselves. PBers would use the forum primarily for problem resolution and logically this will occur quicker on the Aprelium site as questions will be exposed to more AWS experts here than elsewhere, result, happier PB developers singing the praises of Abyss etc etc
Back to top View user's profile Send private message
chicks
-


Joined: 22 Jun 2005
Posts: 8

PostPosted: Wed Feb 21, 2007 5:13 pm    Post subject: Reply with quote

ccs wrote:
there are multiple good paths to the same end with software development. PHP is strong, solid, and widely popular. I've only skimmed the surface of RoR but it too seems like a very useful system. For many old VB programmers though (and those of us who have mainly use PB for a few decades now!) PB is a great choice since the learning curve is low, the executables are small, fast, and easy to use for web apps.


You can use a combination of PHP and PB if you like, PHP for the web front-end stuff, and PB for the backend business logic, etc. FastCGI allows you to run an fcgi server remotely from your web server, as the PB example above demonstrates. Abyss could be running on a linux box with PHP scripts for the dynamic html stuff, with remote fcgi calls to your PB fcgi server running on another Windows box behind the firewall, talking to your database of choice.

I notice folks on the PB forums discussing local fcgi's, has anyone tried the remote version above?
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> FastCGI/CGI All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group