Page 1 of 1

SCGI

Posted: Wed Mar 19, 2014 12:41 pm
by infratec
Hi,

I need now a web script which accesses a database and this very often by many clients.
Up to now I used a CGI program written in PB.
But always loading the program needs to long and is inefficient.

So I looked for the well known FastCGI...

But I could not get a friend of it.
After 2 days I found SCGI: That's it :!:

Install the module, enable it
a2enmod mod_scgi
and add something like

Code: Select all

<Location "/scgi">
  SGIHandler On
</Location>
SCGIMount /scgi 127.0.0.1:4000
in your apache site.conf file.
You don't need to create /scgi physically.

Than use this PB code as first test base for a SCGI server:

Code: Select all

InitNetwork()

Server = CreateNetworkServer(#PB_Any, 4000, #PB_Network_TCP,  "127.0.0.1")
If Server
  
  *Buffer = AllocateMemory(1024)
  If *Buffer
    
    Repeat
      If NetworkServerEvent() = #PB_NetworkEvent_Data
        Client = EventClient()
        Size = ReceiveNetworkData(Client, *Buffer, MemorySize(*Buffer))
        If Size
          
          Answer$ = "Status: 200 OK" +#CRLF$
          Answer$ + "Content-type: text/plain" + #CRLF$
          Answer$ + #CRLF$
          
          Ptr = 0
          Repeat
            Buffer$ = PeekS(*Buffer + Ptr, -1, #PB_UTF8)
            Ptr + StringByteLength(Buffer$) + 1
            Answer$ + Buffer$ + #CRLF$
          Until Ptr >= Size
          
          SendNetworkString(Client,  Answer$)
          CloseNetworkConnection(Client)
          
        EndIf
      Else
        Delay(10)
      EndIf
    ForEver
    
  EndIf
  
EndIf
To test enter something like this:
http://yourserver/scgi?para=123
in your browser.

This shows you the way...
More work to be done by you :mrgreen:

Bernd

Re: SCGI

Posted: Wed Mar 19, 2014 7:47 pm
by idle
makes things much simpler :)

Re: SCGI

Posted: Wed Mar 19, 2014 8:23 pm
by infratec
And you need no additional lib or something like that.

Re: SCGI

Posted: Thu Mar 20, 2014 3:59 am
by useful
infratec wrote: ...........

I need now a web script which accesses a database and this very often by many clients.
Up to now I used a CGI program written in PB.
But always loading the program needs to long and is inefficient.

So I looked for the well known FastCGI...

............
If I own server, it is all wonderful. As possible examples of commercial hosting, where you can place PB FastCgi?

Re: SCGI

Posted: Thu Mar 20, 2014 9:14 am
by dige
What does this mean? All traffic that goes to SCGI, will be redirected to another network server?

Re: SCGI

Posted: Thu Mar 20, 2014 10:15 am
by infratec
Hi,

SCGI is like FastCGI a solution that the CGI program is not loaded at every call.
It is running as server and so no time for loading and initialization is needed.

The communication between the Web-Server and the 'CGI' is done via network.

This gives further possibilities:

You can run the SCGI program on any machine, not requierd on the Web-Server.
This maybe more secure.

The SCGI program can run as any user and it is not running as the Web-Server user,
which is also more secure.

In my case, where I need as much speed as possible, I run it on the same machine on localhost interface.

At the moment I try to implement multithreading for each client connection.

Hope this answers your questions.

Bernd

Re: SCGI

Posted: Thu Mar 20, 2014 10:50 am
by dige
Bernd, muchas gracias!! :-)

Re: SCGI

Posted: Tue Sep 08, 2015 3:35 pm
by Kiffi
Hello Bernd,
infratec wrote:Install the module
OK (the module was already installed in my XAMPP-Package)
infratec wrote:enable it
OK
infratec wrote:and add something like

Code: Select all

<Location "/scgi">
  SGIHandler On
</Location>
SCGIMount /scgi 127.0.0.1:4000
Doesn't work for me. If i add this lines into the httpd.config, my Apache won't start.
[Apache] Apache shutdown unexpectedly.
[Apache] This may be due to a blocked port, missing dependencies,
[Apache] improper privileges, a crash, or a shutdown by another method.
[Apache] Press the Logs button to view error logs and check
[Apache] the Windows Event Viewer for more clues
[Apache] If you need more help, copy and post this
[Apache] entire log window on the forums
The Apache error.log contains no hint, nor the Windows Eventlog.

Any idea, what i'm doing wrong?

Thanks in advance & Greetings ... Peter

Re: SCGI

Posted: Tue Sep 08, 2015 3:48 pm
by infratec
Hi Kiffi,

I never used XAMPP on windows.
I always use a linux server (Debian) with Apache 2.2 (at the moment)


Oh, httpd.conf ???
I think that's the wrong place.
It should be in the site.conf file.
Somewhere inside the <VirtualHost > tags

Because it belongs to the website and not apache in general.

Else:
Do you run it as Administrator?
Try to switch off the firewall (normally a box should appear to allow access for apache to access the port)

Bernd

Re: SCGI

Posted: Tue Sep 08, 2015 10:51 pm
by Kiffi
Hello Bernd,

thanks for your fast reply! In the meantime i have tried it with EasyPHP and get a more detailed error-message:
AH00526: Syntax error on line 1103 of C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/binaries/apache/conf/httpd.conf:
Invalid command 'SGIHandler', perhaps misspelled or defined by a module not included in the server configuration
But finally i found a solution that works for me:

Code: Select all

ProxyPass /scgi-bin/ scgi://localhost:4000/
Thanks again & Greetings ... Peter